我为家创建了这样的按钮:
UIBarButtonItem * addButton=[[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStyleBordered target:self action:@selector(GoToHome:)];
[navItem setLeftBarButtonItem:addButton];
GoToHome函数只有一行,即:
[self.navigationController popToRootViewControllerAnimated:YES];
但是当我点击主页按钮时,它显示没有动作(不工作)
答案 0 :(得分:2)
在GoToHome方法中尝试这个
[self.parentViewController.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
答案 1 :(得分:1)
您是否已将按钮代码与IB按钮相关联?这可能发生在很多人身上...... !!
答案 2 :(得分:0)
试试这个,
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStylePlain target:self action:@selector(GotoTopScreen)];
self.navigationItem.rightBarButtonItem = addButton;
-(void)GotoTopScreen{
[self.navigationController popToRootViewControllerAnimated:YES];
}
答案 3 :(得分:0)
创建导航控制器的最佳方法是在appDelegate中创建它并将其作为appDelegate.navigationController访问。那些零对象问题不会来。
答案 4 :(得分:0)
使用此方法:
UIBarButtonItem *flipButtons = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered target:self
action:@selector(GotoTopScreen)];
self.navigationItem.leftBarButtonItem = flipButtons;
[flipButtons release];
-(void)GotoTopScreen
{
[self.navigationController popToRootViewControllerAnimated:YES];
}