0

请帮助理解导航。我正在使用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];
    }
}

所以,我有问题:

  1. 我应该在哪里创建下一个视图?在我的代码中,视图已在“上一个”类中创建:在 FirstViewController 中创建的 view2,在 SecondViewController 中创建的 view3 等。所有新的 ViewController 都在启动导航的方法中,是不是正确的方法?我认为这是错误的,但导航工作正常。

  2. 导航栏中的标题问题。原来 view2 的标题只有在从 view1 移动到 view2 时才会显示,但是当从 view3 回到 view2 时 - 标题消失了。我用谷歌搜索,试图添加self.title = @"name"viewDidLoad, initWithNibName, viewWillAppear– 这些都不起作用。

4

1 回答 1

0

所以我已经解决了导航栏标题消失的问题。问题出在我的自定义后退按钮中:self.navigationItem.title = @""; 它正在工作,我的后退按钮的标题“返回”消失了,但导航栏的标题也消失了。使后退按钮无标题的正确方法是:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButton];
于 2013-10-27T20:35:06.740 回答