0

ここのチュートリアルに従って、UINavigationController を使用して ViewController を切り替えます。コードをダウンロードしてチュートリアルに従うと、すべてうまく機能しますが、これを別のアプリに適用しようとすると、次の混乱/問題が発生します。「FirstViewController」にいるとき[self navigationController]、viewController クラスに navigationController がない場合、どうすればアクセスできますか? この例では、firstViewController 内で、navigationController がどのように、またはどこから来るのかを見つけることができません。誰かがこれがどのように機能するか説明してもらえますか?

**注: プロジェクト全体の完全なソース コードは、上記でリンクしたページにもあります。

これは私を混乱させる行です:

[[self navigationController] pushViewController:secondViewController   animated:YES];

これは、viewController のコード全体です。

.h

#import <UIKit/UIKit.h>
@class SecondViewController;

@interface FirstViewController : UIViewController {

    IBOutlet SecondViewController *secondViewController;
}

@property(nonatomic, retain) SecondViewController *secondViewController;

- (IBAction)PressMe:(id)sender;

@end

.m

#import "FirstViewController.h"
#import "SecondViewController.h"


@implementation FirstViewController

@synthesize secondViewController;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"First View";
}

- (IBAction)PressMe:(id)sender
{
    [[self navigationController] pushViewController:secondViewController animated:YES]; //This line
}


- (void)dealloc {
    [super dealloc];
}


@end
4

3 に答える 3

0

IB を使用している場合 (コードに記述したとおり)、ボタンを右クリックして SecondViewController にドラッグし、[Touch Up Inside] を選択します。

于 2012-08-07T20:51:13.550 に答える