我已經搜索了很多關於此主題的內容,但無法獲得此代碼的工作。當我執行它時,它只顯示我的測試NSLog,但從一個視圖到另一個視圖的代碼不會執行任何操作。在這裏,你有下面的代碼:從UITableView單元轉到Detail視圖
//FirstViewController.h
#import <UIKit/UIKit.h>
#import "StationDetailsViewController.h"
@interface FirstViewController : UIViewController{
NSArray *ListaEstaciones;
NSArray *ListaID;
}
@property (nonatomic, retain) NSArray *ListaEstaciones;
@property (nonatomic, retain) NSArray *ListaID;
@end
//FirstViewController.m
#import "FirstViewController.h"
#import "StationDetailsViewController.h"
@implementation FirstViewController
@synthesize ListaEstaciones;
@synthesize ListaID;
//...
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"Pushing...");
StationDetailsViewController *controller = [[StationDetailsViewController alloc] initWithNibName:@"StationDetailsViewController" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
}
@end
我已經試過很多的教程和我的書,但我不知道哪裏不對。非常感謝,夥計們。
編輯:讀你的答案我發現錯誤是在AppDelegate.m其中rootViewController被定義。
//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
我不知道該怎麼在這裏編輯,使這個: [自我navigationController] pushViewController:控制器動畫:是]; 正常工作。
你可能沒有self.navigationController。你有一個導航控制器作爲rootViewController嗎?從基於導航的模板開始 – 2012-02-19 11:36:14
我的應用程序是一個TabBarController,其中第一個選項卡是我在此複製的視圖。在AppDelegate.m我有這個:self.window.rootViewController = self.tabBarController; – 2012-02-19 11:39:17