【问题标题】:iphone-dev: TabBarItem helpiphone-dev: TabBarItem 帮助
【发布时间】:2009-09-25 17:53:57
【问题描述】:

我正在这样设置我的应用程序(在 applicationDidFinishLaunching 中):

mytable = [[[MyTableController alloc] initWithStyle:UITableViewStylePlain] retain];

UINavigationController *mynav =  [[[UINavigationController alloc]initWithRootViewController:mytable] autorelease];

[mynav.view setFrame:CGRectMake(0,0,320,460)];

UIViewController *tab1 = [[tabBarController viewControllers] objectAtIndex:0];

[mytable setTitle:@"Chronological"];

mytable.navigationController = mynav;

[tab1.view addSubview:mynav.view];

[window addSubview:tab1.view];

其中 MyTableController 扩展 UITableController 并具有导航控制器属性。 tabBarController 是一个通过主 nib 文件的出口。没有其他 nib 文件。

我现在无法向导航控制器添加任何按钮。我所做的一切都被忽略了。我在这里做错了什么?

【问题讨论】:

  • [[[MyTableController alloc] initWithStyle:UITableViewStylePlain] retain]: alloc 已经进行了保留。你保留了太多

标签: iphone uinavigationcontroller uinavigationitem


【解决方案1】:

能否包含设置UITabBarController tabBarController 的代码?我猜您没有正确设置 viewControllers 属性。使用UITabBarController -setViewControllers:animated: 和视图控制器数组来初始化标签栏控制器。

试试这样的:

mytable = [[MyTableController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *mynav = [[UINavigationController alloc] initWithRootViewController:mytable];
[tabBarController setViewControllers:[NSArray arrayWithObject:mynav] animated:NO];
[mynav release];
[mytable release];
[tabBarController viewWillAppear:NO];
[window addSubview:[tabBarController view]];
[tabBarController viewDidAppear:NO];

【讨论】:

    猜你喜欢
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多