2010-03-28 53 views
0

我正在尝试构建一个应用程序,其中有4个条目的TabBarController。 当我选择第一个条目时,出现带有UITableView的视图。 这个TableView充满了几个条目。UITabBarController的多个视图

我想要做的是: 当一个输入出UITableView被选中时,应该显示另一个视图;详细视图。

.M

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

if (indexPath.row == 0) { 

if(self.secondView == nil) { 
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]]; 
self.secondView = secondViewController; 
[secondViewController release]; 
} 

// Setup the animation 
[self.navigationController pushViewController:self.secondView animated:YES]; 

} 
} 

.H

#import <UIKit/UIKit.h> 
#import "SecondViewController.h" 


@interface FirstViewController : UIViewController { 

SecondViewController *secondView; 

NSMutableArray *myData; 
} 
@property (nonatomic, retain) SecondViewController *secondView; 
@property (nonatomic, copy, readwrite) NSMutableArray* myData; 

@end 

这是我到目前为止所。

不幸的是..代码运行,第二个视图没有显示出来。

回答

1

是你的第一个视图控制器包装在UINavigationController?当您设置UITabBarController,你应该添加UINavigationControllers而不是你的UIViewController子类,如:

FirstViewController *viewControl1 = [[FirstViewController alloc] init]; 
UINavigationController *navControl1 = [[UINavigationController alloc] initWithRootViewController:viewControl1]; 
UITabBarController *tabControl = [[UITabBarController alloc] init]; 
tabControl.viewControllers = [NSArray arrayWithObjects:navControl1, <etc>, nil]; 
//release everything except tabControl 

此外,根据你的代码,你并不需要保持你的secondViewController作为伊娃,因为UINavigationController的自动保留它的视图控制器(当你不显示它时会保留它)会占用不必要的内存)。

相关问题