2009-08-13 57 views
1

我是iPhone新手,希望獲得關於將某種應用程序放在一起的常規設計模式/指南的建議。將NavigationControl添加到包含UITableViews的TabBar應用程序

我想構建一個TabBar類型的應用程序。其中一個選項卡需要顯示一個TableView,並從表格視圖中選擇一個單元格將會執行其他操作 - 可能會顯示另一個表格視圖或網頁。我需要一個導航欄才能從桌面視圖/網頁中取回我。

到目前爲止,我採取的辦法是:

創建基於周圍的UITabBarController作爲rootcontroller一個應用程序

@interface MyAppDelegate : NSObject <UIApplicationDelegate> 
{ 
IBOutlet UIWindow *window; 
IBOutlet UITabBarController *rootController; 
} 

創建的UIViewController派生類和相關的發鈔銀行的負載並在IB中連接所有東西,所以當我運行應用程序時,我可以使用基本選項卡。

我再取的UIViewController派生類,並將其修改爲以下內容:

@interface MyViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> 
{ 

} 

,我添加的委託方法的MyViewController

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section   { 
return 2; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

if (indexPath.row == 0) 
{ 
    cell.textLabel.text = @"Mummy";  
} 
else 
{ 
    cell.textLabel.text = @"Daddy"; 
} 
return cell; 
} 

實施回去IB,打開MyViewController .xib並將UITableView拖放到它上面。將文件所有者設置爲MyViewController,然後將UITableView的委託和數據源設置爲MyViewController。

如果我現在運行該應用程序,我會得到與木乃伊和爸爸很好地工作的表視圖。到現在爲止還挺好。

的問題是,我怎麼去整合一個導航欄到我當前的代碼,當我實施:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath() 
{ 
// get row selected 
NSUInteger row = [indexPath row]; 

if (row == 0) 
{ 
    // Show another table 
} 
else if (row == 1) 
{ 
    // Show a web view 
} 
} 

難道我滴個導航欄UI控件到MyControllerView.xib?我應該以編程方式創建它嗎?我應該在某處使用UINavigationController嗎?我已經嘗試將NavigationBar拖放到IB的MyControllerView.xib中,但在運行應用程序時未顯示,僅顯示TableView。

回答

相關問題