iPhone导航后退按钮 [英] iPhone Navigation Back Button

查看:82
本文介绍了iPhone导航后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是后退按钮没有显示在SettingsViewController上。导航栏会在按下视图时显示,但没有后退按钮。

I am having issues with the back button not showing up on the SettingsViewController. The navigation bar does show up when the view is pushed, but no back button.

我在视图控制器中创建了这个,它不是导航控制器。关于这里实际发生的事情的任何想法或建议。

I am creating this inside a view controller, which is not a navigation controller. Any ideas or suggestions on what is actually going on here.

- (void)viewDidLoad
{
    self.title = @"Settings";
}

- (IBAction)showSettingsModal:(id)sender 
{    
    SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:settingsViewController] autorelease];

    [self presentModalViewController:navController animated:YES];
    [settingsViewController release];    
}


推荐答案

您正在创建新的导航叠加。您需要添加自己的后退按钮并将其操作设置为调用VC上的委托方法以解除它。

You are creating a new navigation stack. You will need to add your own Back button and set the action of that to a delegate method on the calling VC to dismiss it.

更新:
似乎关于在哪里以及如何解雇ModalViewControllers会有很多困惑。在大多数情况下,错误的做法是如果您希望父母对该解雇采取行动,请从Modal VC本身调用Dismiss方法。相反,使用委托。这是一个简单的例子:

UPDATE: There seems to be lots of confusion about where and how to dismiss ModalViewControllers. The wrong thing to do in most cases is to call the Dismiss method from the Modal VC itself if you are wanting the parent to act on that dismissal. Instead, use delegation. Here is a simple example:

ModalViewController.h:

ModalViewController.h:

@protocol ModalViewControllerDelegate
-(void)dismissMyModalVC;
@end


@interface ModalViewController : UIViewController {
id < ModalViewControllerDelegate > delegate;
}

@property (nonatomic, retain) id < ModalViewControllerDelegate > delegate;
// The rest of your class properties, methods here

ModalViewController.m

ModalViewController.m

@synthesize delegate;

...

// Put in the Method you will be calling from that Back button you created
[delegate dismissMyModalVC];

CallingViewController.h:

CallingViewController.h:

#import "ModalViewController.h"

@interface CallingViewController : UIViewController 
<ModalViewControllerDelegate> 
// Rest of class here

CallingViewController.m:

CallingViewController.m:

ModalViewController *mvc = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];
mvc.delegate = self
[self presentModalViewController:mvc animated:YES];

...

// The ModalViewController delegate method
-(void)dismissMyModalVC {
// Dismiss the ModalViewController that we instantiated earlier
[self dismissModalViewControllerAnimated:YES];

这样VC就会从实例化它的控制器中正确解散。可以修改该委托方法以传递对象(例如,当您完成对用户的登录等时)

That way the VC gets dismissed properly from the controller that instantiated it. That delegate method can be modified to pass along objects as well (like when you are finished logging a user in, etc)

这篇关于iPhone导航后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆