UITabController iPhone 开发

发布于 2024-07-26 14:50:56 字数 2075 浏览 2 评论 0原文

我正在关注 Iphone UI 选项卡控制器教程,我基本上模仿了底部的代码 链接文本

// 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 只是默认的空视图,我只更改了背景以确保它们正在加载。 当我运行此命令时,第一个视图会加载,但我无法单击选项卡栏在视图之间进行更改,我是否遗漏了某些内容?

I am following the Iphone UI tab controller tutorial, I basically mimicked the code at the bottom
link text

// 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 and PhoneContacts are just default empty view, I only changed there background to make sure they were loading.
When I run this, The first view loads, but I am unable to click on the Tab Bar to change between the view's am I missing something ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水溶 2024-08-02 14:50:56

发现BUG:

[window addSubview:tabBarController.view];
[tabBarController release]; <------------- I am releasing the tabBarController while still in use 
[window makeKeyAndVisible];

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

Found the BUG:

[window addSubview:tabBarController.view];
[tabBarController release]; <------------- I am releasing the tabBarController while still in use 
[window makeKeyAndVisible];

Thats why the tab bar controller was unresponsive.
-daniel

美羊羊 2024-08-02 14:50:56

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

If OtherContacts and PhoneContacts are "UIView" classes and not UIViewController classes, that would explain the problems - the tab bar controller needs UIViewController references.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文