1

我的应用程序正在使用 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];

}

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

4

2 回答 2

1
UIButton* backButton = [UIButton buttonWithType:101];

我很确定“101”无效

+ (id)buttonWithType:(UIButtonType)buttonType

您应该使用以下 UIButtonType 值之一

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

除了测试你的代码在你的dismissView中放置一些NSLog:看看它是否被调用

于 2012-01-17T04:42:26.347 回答
1

请在您的 dissmissView 中使用 NSLog

-(void) dismissView: (id)sender

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

}

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

于 2012-01-17T04:49:38.660 回答