Objective c 在iOS应用程序中使用xib进行导航
请帮助理解导航。我在和xibs合作。该计划为:。 这是我的密码: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
@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];
}
}
因此,我有一些问题:
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中创建它。我真的没发现你贴的有什么问题。