我的应用程序使用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];
}
但是当我按下完成按钮时没有任何反应。那是为什么?
答案 0 :(得分:1)
UIButton* backButton = [UIButton buttonWithType:101];
我很确定“101”无效
+ (id)buttonWithType:(UIButtonType)buttonType
您应该使用以下UIButtonType值之一
typedef enum {
UIButtonTypeCustom = 0,
UIButtonTypeRoundedRect,
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
} UIButtonType;
除了那个测试之外,你的代码在你的dismissView中放了一些NSLog:看它是否被调用
答案 1 :(得分:1)
请NSLog登录您的dissmissView
-(void) dismissView: (id)sender
{
NSLog(@"Hii....");
[self.navigationController popToRootViewControllerAnimated:YES];
//[self.navigationController popToViewController:_viewController animated:YES];
}
或使用断点调试应用程序。