请帮助理解导航。我正在使用xibs。该方案是:https://www.dropbox.com/s/o82fxpte0hmyxcq/Scheme_Simple.jpg。这是我的代码:
@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 时 - 标题消失了。我用谷歌搜索,试图添加
self.title = @"name"
到viewDidLoad
,initWithNibName
,viewWillAppear
– 这些都不起作用。