1

使用pushViewController显示导航控制器模态pushViewController和popToRootViewController

[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

你在哪里把这个代码初始化完成按钮?你有没有尝试在“dismissView:”选择器中添加一条NSLog语句以确定它是否实际被调用? – nickbona 2012-01-16 21:59:03

+0

如何初始化完成按钮? – user1120133 2012-01-16 22:08:12

回答

1

请NSLog在您的dissmissView

-(void) dismissView: (id)sender 

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

} 

或用断点调试应用程序。

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

IM相当肯定 “101” 是无效的

+ (id)buttonWithType:(UIButtonType)buttonType 

你应该使用下列UIButtonType的一个值

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

比测试你的代码把一些的NSLog你dismissView其他:看看它是否被称为