通过带导航控制器的按钮返回主视图

时间:2011-07-12 13:03:22

标签: iphone ios uinavigationcontroller

嗨我有一个带导航控制器的课程,在我的主课程中我用这段代码隐藏了导航栏。 [self.navigationcontroller setnavigationbarHidden:YES];

我想知道,当我推送到next.xib文件时,我怎么能回到main按钮。

3 个答案:

答案 0 :(得分:1)

[self.navigationController popViewControllerAnimated: YES]

如果您想使用按钮,请添加按钮,并设置其动作处理程序以调用该方法。 例如你有

UIButton *backButton; 

并设定其行动,

 [backButton addTarget:self action:@selector(didPressBackButton) 
forControlEvents:UIControlEventTouchUpInside

然后,

- (void) didPressBackButton {
[self.navigationController popViewControllerAnimated: YES]
}

答案 1 :(得分:1)

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006934

- (UIViewController *)popViewControllerAnimated:(BOOL)animated

[self.navigationController popViewControllerAnimated: YES]

创建一个按钮并向其添加操作

[button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];

然后创建back方法

-(void)back:(id)sender
{
   [self.navigationController popViewControllerAnimated: YES]
}

答案 2 :(得分:0)

您可以创建自定义按钮,并将以下代码添加到其方法调用中。

[self.navigationController popViewControllerAnimated:YES];

相关问题