PushViewController 和 popToRootViewController

发布于 2024-12-27 11:25:54 字数 845 浏览 1 评论 0原文

我的应用程序正在使用pushViewController以模态方式显示导航控制器

 [navigationController pushViewController:_viewController animated:YES];

导航控制器已完成按钮

UIButton* backButton = [UIButton buttonWithType:101]; 
[backButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:@"Done" forState:UIControlStateNormal];

UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

self.navigationItem.leftBarButtonItem = backItem;
[backItem release];

当按下完成按钮时我希望它应该导航回主窗口

-(void) dismissView: (id)sender

{
    [self.navigationController popToRootViewControllerAnimated:YES];
//[self.navigationController popToViewController:_viewController animated:YES];

}

但是当我按下完成按钮时什么也没有发生。这是为什么?

My application is using pushViewController to show the navigation controller modally

 [navigationController pushViewController:_viewController animated:YES];

Navigation Controller has done button

UIButton* backButton = [UIButton buttonWithType:101]; 
[backButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:@"Done" forState:UIControlStateNormal];

UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

self.navigationItem.leftBarButtonItem = backItem;
[backItem release];

When done button is pressed I want that it should navigate back to main window

-(void) dismissView: (id)sender

{
    [self.navigationController popToRootViewControllerAnimated:YES];
//[self.navigationController popToViewController:_viewController animated:YES];

}

But when I press on done button nothing happens. Why is that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假装不在乎 2025-01-03 11:25:54

请在您的 dissmissView 中 NSLog

-(void) dismissView: (id)sender

{
   NSLog(@"Hii....");
    [self.navigationController popToRootViewControllerAnimated:YES];
//[self.navigationController popToViewController:_viewController animated:YES];

}

或使用断点调试应用程序。

Please NSLog in your dissmissView

-(void) dismissView: (id)sender

{
   NSLog(@"Hii....");
    [self.navigationController popToRootViewControllerAnimated:YES];
//[self.navigationController popToViewController:_viewController animated:YES];

}

or debug the app with break point.

简美 2025-01-03 11:25:54
UIButton* backButton = [UIButton buttonWithType:101];

我很确定“101”无效,

+ (id)buttonWithType:(UIButtonType)buttonType

您应该使用以下 UIButtonType 值之一

typedef enum {
    UIButtonTypeCustom = 0,
    UIButtonTypeRoundedRect,
    UIButtonTypeDetailDisclosure,
    UIButtonTypeInfoLight,
    UIButtonTypeInfoDark,
    UIButtonTypeContactAdd,
} UIButtonType;

,而不是测试您的代码,在您的missView中放入一些 NSLog:以查看它是否被调用

UIButton* backButton = [UIButton buttonWithType:101];

im quite sure "101" is invalid

+ (id)buttonWithType:(UIButtonType)buttonType

you should use one of the following UIButtonType values

typedef enum {
    UIButtonTypeCustom = 0,
    UIButtonTypeRoundedRect,
    UIButtonTypeDetailDisclosure,
    UIButtonTypeInfoLight,
    UIButtonTypeInfoDark,
    UIButtonTypeContactAdd,
} UIButtonType;

other than that test your code put some NSLog in your dismissView: to see if it gets called

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文