2012-02-19 13 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

コーディングお楽しみのコード行にブレークポイントを入れて、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 *を書くことを意味しますか?[[UINavigationController alloc] initWithRootViewController:FirstViewController]; AppDelegate.mのdidLinunchingWithOptionsに がありますか? –

0

データソースとデリゲート設定、またはナビゲーションコントローラに問題があると思います。

チェックこれはあなたに役立つかもしれないこのチュートリアルUITableView Tutorial

そのcuzのゼロ =あなたが..私は問題がに[自己navigationController]だと思います:)

関連する問題