Objective c 在iOS应用程序中使用xib进行导航

Objective c 在iOS应用程序中使用xib进行导航,objective-c,navigation,xib,xcode5,viewcontroller,Objective C,Navigation,Xib,Xcode5,Viewcontroller,请帮助理解导航。我在和xibs合作。该计划为:。 这是我的密码: @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bound

请帮助理解导航。我在和xibs合作。该计划为:。 这是我的密码:

@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];
    }
}
因此,我有一些问题:

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

  • 导航栏中的标题有问题。事实证明,view2的标题仅在从view1移动到view2时显示,但在从view3返回到view2时,标题将消失。我在谷歌上搜索,试图将
    self.title=@“name”
    添加到
    viewDidLoad
    initWithNibName
    视图将出现
    ——这些都不起作用


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

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:backButton];
    

    回答第1点。我认为这是正确的。第2点。从您粘贴到这里的代码来看,它应该可以正常工作。您正在使用导航控制器中的内置后退按钮?是的,我不使用自定义导航项或导航栏。默认情况下,代码的其余部分不做任何操作。可能是因为我应该在interface builder中创建导航栏、创建插座、属性等?不,如果不想,您不需要在interface builder中创建它。我真的没发现你贴的有什么问题。