首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITabController iphone开发

UITabController iphone开发
EN

Stack Overflow用户
提问于 2009-07-08 03:34:26
回答 2查看 1.2K关注 0票数 0

我正在学习Iphone UI选项卡控制器教程,我基本上模仿了底部link text的代码

代码语言:javascript
复制
// Create a temporary window object to assign to the window property 
    UIWindow *tempWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]
 bounds]];
    // Make the window background red so that you can see that the window has been added
    tempWindow.backgroundColor = [UIColor grayColor];
    self.window = tempWindow;
    [tempWindow release];


    // add the tab bar controller
    UITabBarController *tabBarController;
    tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];


    PhoneContactsView *phoneContactsView = [[[PhoneContactsView alloc] init] autorelease];
    OtherContactsView *otherContactsView = [[[OtherContactsView alloc] init] autorelease];

    //Add all the view to the tabBarView
    tabBarController.viewControllers = [NSArray arrayWithObjects:otherContactsView,phoneContactsView, nil];

    //Add all the button's to the bar

    UITabBarItem *otherContactsTabBarItem = 
    [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:1];       
    otherContactsBarItem.title = @"My Contacts";
    otherContactsView.tabBarItem = otherContactsBarItem;    
    [otherContactsBarItem release];

    UITabBarItem *phoneContactsBarItem =
    [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1];       
    phoneContactsView.tabBarItem = phoneContactsBarItem;    
    [phoneContactsBarItem release];

    tabBarController.selectedViewController
    = [tabBarController.viewControllers objectAtIndex:0];

    [window addSubview:tabBarController.view];
    [tabBarController release];
    [window makeKeyAndVisible];

OtherContacts和PhoneContacts只是默认的空视图,我只是更改了它们的背景以确保它们是加载的。当我运行此命令时,加载了第一个视图,但我无法单击选项卡栏在视图之间切换我是否遗漏了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-07-08 05:28:06

找到错误:

代码语言:javascript
复制
[window addSubview:tabBarController.view];
[tabBarController release]; <------------- I am releasing the tabBarController while still in use 
[window makeKeyAndVisible];

这就是标签栏控制器没有响应的原因。-daniel

票数 1
EN

Stack Overflow用户

发布于 2009-07-08 03:38:53

如果OtherContacts和PhoneContacts是"UIView“类而不是UIViewController类,这就解释了问题--选项卡栏控制器需要UIViewController引用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1096025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档