我已经搜索了很多关于此主题的内容,但无法获得此代码的工作。当我执行它时,它只显示我的测试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