请帮助了解导航。我正在与xibs合作。该计划是:https://www.dropbox.com/s/o82fxpte0hmyxcq/Scheme_Simple.jpg。 这里是我的代码:在iOS应用程序中使用xib导航应用程序
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
FirstViewController *firstViewController = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
@implementation FirstViewController
- (IBAction)button1Tapped:(id)sender {
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.title = @"View2";
[self.navigationController pushViewController:secondViewController animated:YES];
}
@implementation SecondViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
thirdViewController.title = @"View3";
if (indexPath.row == 0) {
[self.navigationController pushViewController:thirdViewController animated:YES];
[secondViewTableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
所以,我有疑问:
我应该在哪里创建下一个看法?在我的代码视图中创建了“前一个”类:在FirstViewController中创建的view2,在SecondViewController中创建的view3等。所有新的ViewController都在启动导航的方法中,是正确的方式吗?我认为这是错误的,但导航正在工作。
导航栏中标题的问题。事实证明,view2的标题仅在从view1移动到view2时显示,但是当从view3返回到view2时 - 标题消失。我使用Google搜索,试图添加
self.title = @"name"
到viewDidLoad
,initWithNibName
,viewWillAppear
- 这些都不起作用。
要回答点1.我会说这是正确的。 要点2.从您粘贴的代码中,它应该按预期工作。您正在使用导航控制器中的内置后退按钮? –
是的,我不使用自定义导航项目或导航栏。其余的代码是默认的,什么都不做。也许原因是我应该在界面构建器中创建导航栏,创建出口,属性等? –
不,您不需要在界面构建器中创建它,如果您不想。我真的无法找到你发布的任何内容。 –