2009-08-13 58 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。

回答

相关问题