2010-03-28 5 views
0

4 개의 항목이있는 TabBarController가있는 응용 프로그램을 만들려고합니다. 첫 번째 항목을 선택하면 UITableView가있는보기가 표시됩니다. 이 TableView는 여러 항목으로 채워져 있습니다.UITabBarController의 다중 뷰

내가 무엇을하고 싶은지 : 그 UITableView 밖으로 항목이 선택되면 다른보기가 나타나야합니다; 세부 사항.

하는 .m 이것은 내가 지금까지 무엇을 가지고 .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 

- (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]; 

} 
} 

.

불행히도 .. 코드가 실행되고 두 번째보기가 표시되지 않습니다.

답변

1

첫 번째보기 컨트롤러가 UINavigationController으로 묶여 있습니까? 당신이 당신의 UITabBarController을 설정할 때 예를 들어, 오히려 당신의 UIViewController 서브 클래스보다 UINavigationControllers을 추가해야합니다 :

또한
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 

, 당신의 코드를 기반으로, 당신은 UINavigationController가 자동으로 유지하기 때문에, 바르로 secondViewController을 보관할 필요가없는 그것의보기 컨트롤러 (그리고 당신이 그것을 표시하지 않을 때 그것을 유지하는 것은 불필요한 메모리를 다 쓸 것이다).

관련 문제