2010-03-28 39 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的自動保留它的視圖控制器(當你不顯示它時會保留它)會佔用不必要的內存)。

相關問題