2012-02-19 4 views
1

Я много искал об этой теме, и я не могу получить этот код. Когда я его выполняю, он показывает только мой тест NSLog, но код, который следует переходить с одного взгляда на другой, ничего не делает. Здесь у вас есть следующий код:Перейдите из ячейки UITableView в подробный вид

//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 

Я пробовал много учебники и мою книгу, но я не знаю, что не так. Большое спасибо, ребята.

EDIT: прочитав ответы, я обнаружил, что ошибка находится на 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: контроллер анимации: YES]; исправно работает.

+1

у вас, вероятно, нет self.navigationController. У вас есть контроллер навигации как rootViewController? Начните с шаблона на основе навигации –

+0

Мое приложение - TabBarController, первая вкладка которого является видом, который я скопировал здесь. В AppDelegate.m у меня есть это: self.window.rootViewController = self.tabBarController; –

ответ

0

я думаю, что проблема в [себе navigationController] .. поставить точку останова на эту строку кода и probaly вы найдете его значение = ноль Потому что того, что вы не имея контроллер подробно .. вы могли бы решить эту проблему, как этот UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:yourMainViewControllerInstance];

этого AppDelegate код:

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
// Override point for customization after application launch. 
UIViewController *firstViewController = [[[FirstViewController alloc] initWithNibName:@"FBConFirstViewController" bundle:nil] autorelease]; 
UIViewController *secondViewController = [[[SecondViewController alloc] initWithNibName:@"FBConSecondViewController" bundle:nil] autorelease]; 
self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:firstViewController]autorelease]; 
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav, secondViewController, nil]; 
self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 
+0

Где я должен поставить эту строку кода? Внутри didSelectRowAtIndexPath? –

+0

Нет в классе, из которого вы представляете FirstViewController. –

+0

Вы хотите написать UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController: FirstViewController]; в didFinishLaunchingWithOptions в AppDelegate.m? –

0

Я думаю, что есть некоторая проблема либо с параметрами источника данных и делегата, либо с вашим навигационным контроллером.

Проверить этот учебник UITableView Tutorial

Это может быть полезно для вас.

Наслаждайтесь Coding :)

Смежные вопросы