【问题标题】:UINavigationController and UITableViewUINavigationController 和 UITableView
【发布时间】:2011-05-04 04:42:41
【问题描述】:

我想创建一个视图,其中顶部有一个导航栏,而 uitableview 作为内容,底部有一个 uitabbar。我想以编程方式创建所有这些,而不必使用 xib.. 我该怎么做??

到目前为止我有:

@interface GroupViewController : UINavigationController <UITableViewDelegate, UITableViewDataSource>{
    UITableView * table;
    UITabBar * bar;

}

@property (nonatomic, retain) UITableView * table;
@property (nonatomic, retain) UITabBar * bar;

@end

UITabBarItem 点击时会弹出一个窗口(不切换视图,因为如果是这种情况,我需要一个 UITabBarViewController)。

我还有一个问题是在这个整体视图中我应该在哪里指定 UITabBar 的位置?在 UIViewDidLoad 中?

【问题讨论】:

    标签: iphone objective-c ipad


    【解决方案1】:

    您需要从基于视图的应用程序开始。然后在你的 appDelegate 文件中创建一个 UITabbarController。

    Appdelegate.h
    
    UITabBarController *tabBarController;
    // set properties
    
    
    Appdelegate.m
    
    // Synthsize
    
    tabBarController = [[UITabBarController alloc] init];
    tabBarController.delegate=self;
    
    //Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController  
    Search * search = [[Search alloc] init];  
    UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];  
    
    Nearby* nearby = [[Nearby alloc] init];  
    UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];  
    
    Map* map = [[Map alloc] init];  
    UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];  
    
    AboutUs* aboutUs = [[AboutUs alloc] init];  
    UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];  
    
    Favorites* favorites = [[Favorites alloc] init];  
    UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];  
    
    NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];  
    

    tabBarController.viewControllers = 控制器;

    [window addSubview:tabBarController.view];    
    

    您可以相应地管理要将导航控制器或视图控制器放置在哪个选项卡中。

    然后在上面提到的每个视图控制器中你需要实现

    - (id)init {}  
    

    您可以在其中设置选项卡名称和图像。

    【讨论】:

    • 你误解了我的问题......正如我所说,当我点击 UITabBarItem 时,它不会加载新视图......只是一个弹出窗口......我还需要一个 UITabBarController 吗?即:无论您按什么 UITabBarItem,UITableView 都会永久存在
    • 是的。您需要使用 UITabBarController 启动您的应用程序。我不知道为什么你的标签栏项目没有显示你想要的。为此,我需要查看更多您的代码。但只需尝试以这种方式实现它。
    【解决方案2】:

    在loadview方法中创建所有东西(导航栏,uitableview,tabbar)。

    【讨论】:

    • 我必须在加载视图中分配?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多