【问题标题】:uitabbarcontroller / uitabbar in navigation based projectuitabbarcontroller / uitabbar 在基于导航的项目中
【发布时间】:2011-07-02 06:17:48
【问题描述】:

我创建了基于导航的项目。在第二个屏幕中我想添加 uitabbarcontroller。任何人都可以建议我如何做到这一点。

我已经做了很多搜索,但还没有成功。所以请您提供一个简单的示例。我已经尝试过下面的讨论,但我认为这不是一个好方法。

Navigation Based Application with TabBar

谢谢

【问题讨论】:

    标签: ios4 uinavigationcontroller uitabbarcontroller uitabbar


    【解决方案1】:

    其实这是正确的做法。不正确的一件事是控制器的分配位置。这发生在前一个控制器中,即进行推送的控制器中,但应该分配在负责的对象 TabBarController 中。

    当您实现显示 UITabBarController 的操作时,请编写以下代码:

    - (void) theAction {
       SomeTabBarControllerSubClass *controller = [[SomeTabBarControllerSubClass alloc] init];
       [self.navigationController pushViewController:controller animated:YES];
       [controller release];
    }
    

    那么当你实现 SomeTabBarControllerSubClass 类时:
    (.h)

    @interface SomeTabBarControllerSubClass : UITabBarController {
       UIViewController *first;
       UIViewController *second;
    }
    
    @end
    

    (.m)

    @implementation SomeTabBarControllerSubClass
    
    - (void) viewDidLoad {
       first = [[UIViewController alloc] init]; //Or initWithNib:
       second = [[UIViewController alloc] init];
    
       first.view.backgroundColor = [UIColor greenColor] //Just example
       second.view.backgroundColor = [UIColor redColor] //Just example
       first.tabBarItem.image = [UIImage imageNamed:@"someImage.png"];
    
       self.viewControllers = [NSArray arrayWithObjects:first,second,nil];
    }
    
    - (void) dealloc {
       [first dealloc];
       [second dealloc];
       [super dealloc];
    }
    
    @end
    

    【讨论】:

    • self.viewControllers = [NSArray arrayWithObject:first,second,nil];这里将是 self.viewControllers = [NSArray arrayWithObjects:first,second,nil];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多