參考下面的代碼。如果你想使用pushViewController方法。 你必須有一個NavigationViewController。 所以,你的結構有點複雜。一個ViewController具有兩個TableViewController的數量。一個ViewController沒有NavigationController。 NavigaitonViewController在運行時一定屬於應用程序,因爲它應該被配置。
TwoTableViewsAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *naviController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
[window setRootViewController:naviController];
[window makeKeyAndVisible];
return YES;
}
TwoTableViewsViewController.m
- (void)viewDidLoad {
if (firstController == nil) {
firstController = [[FirstTVContoller alloc] init];
}
if (secondController == nil) {
secondController = [[SecondTVController alloc] init];
}
[firstTable setDataSource:firstController];
[secondTable setDataSource:secondController];
[firstTable setDelegate:firstController];
[secondTable setDelegate:secondController];
firstController.view = firstController.tableView;
secondController.view = secondController.tableView;
firstController.rootViewController = self;
secondController.rootViewController = self;
[super viewDidLoad];
}
FirstTVContoller.h,SecondTVController.h
#import <Foundation/Foundation.h>
@interface FirstTVContoller : UITableViewController <UITableViewDataSource, UITableViewDelegate>{
NSMutableArray *items;
}
@property (nonatomic, retain) UIViewController *rootViewController;
@end
FirstTVContoller.m,SecondTVController.m
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
VerticalDetailViewController *verticalDetailViewController = [[VerticalDetailViewController alloc] initWithNibName:@"VerticalDetailViewController" bundle:nil];
[[self.rootViewController navigationController] pushViewController:verticalDetailViewController animated:YES];
}
在我認爲你的問題是太曖昧了。究竟是什麼問題?請多解釋一下? – 2012-08-04 14:11:19
此示例項目指導我向一個視圖控制器添加兩個表視圖:https://github.com/vikingosegundo/my-programming-examples/tree/master/TwoTableViews didSelectRow ..方法正常,但我無法推送任何視圖控制器,當我點擊表視圖中的任何單元格。 – gokhangultekin 2012-08-04 14:20:23
我正在看它現在你的示例代碼項目。你的pushViewController代碼在哪裏?你說推,這是什麼意思?通常,推動平均值是以下代碼。 [[self navigationController] pushViewController:yourViewController]]; – 2012-08-04 14:32:06