2011-08-23 47 views
0

您好,我目前正在測試如何開發一個應用程序,它有幾個與他們自己的父/子結構,從主菜單訪問的tableviews。以編程方式創建uitableview

我想知道如何使用uinavigationcontroller菜單生成新的tableview,但共享uitabbar,因爲這是我第一次嘗試這樣的東西,通常我只是堅持使用蘋果模板。

下面是我想要實現的一般原理,任何意見建議代碼示例都將非常感謝,並且從那裏我可以自己完成工作,它更像是一個問題,從哪裏開始: )

enter image description here

到目前爲止,我有主窗口中設置了一個UIAction捕捉不同的按鈕點擊,我需要弄清楚如何讓所有的孩子們分享的具體UITabbar,然後如何設置等等如果需要,各個分支都有自己的UINavigationController菜單。

這是我UIAction

//Delegate.m 
//--- Caputer button clicks --- 
- (IBAction)buttonClick: (UIButton *) sender 
{ 
    if ([sender isEqual:orangeButton]) { 
     NSLog(@"orangeButton Pressed"); 
    } 
    else if ([sender isEqual:blueButton]) { 
     NSLog(@"blueButton Pressed"); 
    } 
    else if ([sender isEqual:greenButton]) { 
     NSLog(@"greenButton Pressed"); 
    } 
    else if ([sender isEqual:purpuleButton]) { 
     NSLog(@"purpleButton Pressed"); 
    } 
} 
+0

所以我決定做的不是創建一個基於導航的應用程序,然後在第一個視圖上隱藏導航欄,因爲這是dosnt擁有它的唯一視圖。我通過調用 ** [self.navigationController setNavigationBarHidden:YES animated:NO]; ** viewDidLoad –

回答

1

如果你創建了一個「基於的TabBar應用程序」,然後添加navigationController爲所需的選項卡是很容易的。拖動在主窗口中的「UINavigationController的」 的「標籤欄控制器」:

enter image description here

至於「如何生成tableViews」,最簡單的方法是創建一個通用的TableView,叫它LevelTableView.h/.M文件(它可能有它自己的.xib),在這裏你可以添加任何你想,然後,不斷創造新的ViewControllers,例如,在此的tableView的水平:

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    LevelTableView *anotherLevel = [[LevelTableView alloc] initWith...]; 
    [self.navigationController pushViewController:anotherLevel animated:YES]; 
    [anotherLevel release]; 
} 

問題是,這個「Leve lTableView「只創建一次,但爲每個要添加的級別實例化不同的時間,內容是唯一發生變化的內容。

+0

我看到,酷現在嘗試工作,雖然現在..關於UITabBar我不想mainnwindow.xib有一個..所以在這種情況下,因爲uitabbar將永遠是相同的,只要將它添加到每個需要它的視圖。 –

0

將導航控制器添加到標籤欄控制器中。然後隱藏NavigationController並根據您的架構使用工具欄彈出並導航您的視圖。

0

我有這樣的東西。我要做的是,我創建了一個不同的類,我稱之爲「TabBarController」,並在那裏我初始化一切都去我的標籤不同的觀點:

UIViewController *viewController1 = [[FirstTab alloc] initWithNibName:@"FirstTab" bundle:NSBundle.mainBundle]; 
    UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:viewController1];   
    UIViewController *viewController2 = [[SecondTab alloc] initWithNibName:@"SecondTab" bundle:NSBundle.mainBundle]; 
    UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:viewController2]; 
    myTabBarController = [[UITabBarController alloc] init]; 
    myTabBarController.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, nil];  

然後當上的一個按鈕,用戶點擊主視圖這是我做的:

- (IBAction)yourAction:(id)sender { 

TabBarController *tabBarController1 = [[TabBarController alloc] init]; 
tabController.selectedIndex = 1; ==> chose which tab you want to show 
[[[UIApplication sharedApplication]delegate].window setRootViewController:tabBarController1.myTabBarController]; 

} 

這個工作是否相當不錯。