设置导航栏标题

时间:2010-10-01 06:54:44

标签: iphone objective-c uinavigationcontroller uitabbarcontroller

我目前在我的appDelegate中定义了我的导航控制器(代码汇总):

- (void) applicationDidFinishLaunching {
tabBarController = [[UITabBarController alloc] init];

    FlagList *flagList = [[FlagList alloc] initWithApiCall:API_PUBLICTIMELINE andTitle:@"Home"];

    UITabBarItem *homeTab = [[UITabBarItem alloc] initWithTitle:@"Home" 
                                                          image:[UIImage imageNamed:@"home.png"] 
                                                            tag:0];
    flagList.tabBarItem=homeTab;
    [homeTab release];

    tabBarController.viewControllers=[NSArray arrayWithObjects:flagList,nil];
    [flagList release];


    [rootViewController release];
    rootViewController = [[UINavigationController alloc] initWithRootViewController:[tabBarController autorelease]];
    rootViewController.navigationBar.barStyle=UIBarStyleDefault;
}

我想在FlagListView的navigationBar中设置标题。但是,我希望能够在我的FlagList UITableViewController类的-viewDidLoad方法中执行此操作。我该如何访问这个属性?

我试过了:

[[self navigationItem] setTitle:@"Home"];

..但它似乎不起作用。有人可以告诉我我做错了吗?

2 个答案:

答案 0 :(得分:1)

假设如果ViewController使用[self setTitle:@"Home"]代替[[self navigationItem] setTitle:@"Home"];

,则FlagList是后代

答案 1 :(得分:0)

[self setTitle:@“Home”];

这应该有用。