未显示对导航控制器所做的更改

时间:2014-11-20 11:52:45

标签: ios objective-c uinavigationcontroller

我复制了来自View Controller Catalog for iOS的示例,对颜色进行了一些更改,并希望看到它们在模拟器上反映出来。什么都没发生?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

UIViewController *myViewController = [[MyViewController alloc] init];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];

[navigationController setNavigationBarHidden:NO animated:YES];

navigationController.title = @"Hello";

navigationController.navigationBar.barStyle = UIBarStyleBlack ;

navigationController.navigationBar.translucent = NO;

navigationController.navigationBar.tintColor = [UIColor blackColor];

navigationController.navigationBar.barTintColor = [UIColor greenColor];

UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

window.rootViewController = navigationController;

[window makeKeyAndVisible];

return YES; }

我做错了什么?

1 个答案:

答案 0 :(得分:0)

以下几点:首先:确保在目标应用的常规信息中,在Main Interface字段中为空。 (如果找不到,请删除所有* .storyboard文件。)

第二:在AppDelegate.h中应该是这个属性:

@property (strong, nonatomic) UIWindow *window;

最后:在您的代码中更改此内容:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

self.window.rootViewController = navigationController;

[self.window makeKeyAndVisible];

为了逐步了解变化。 (.title在ViewController中)。