1

私は2つのViewControllerクラスを持っています。1つはfirstviewController、もう1つはfirst viewcontrollerのsecondViewControllerです。これ[self dimissModalViewControllerAnimation:NO]; を呼び出して、ビューを閉じます。今、私は別のsecondViewControllerクラスから同じビューを却下する必要があります。

だから私はその中でスーパーを呼び出す必要がありますか?

[super dismissModalViewControllerAnimated:NO];

または、ビューを閉じるためのプロトコルを作成する必要がありますか?別のsecondViewControllerクラスから。

この問題について誰かが私を導くことができますか?

4

2 に答える 2

1

superメソッド定義をオーバーロードする場合にのみ使用する必要があります。例:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = @"Login / Signup";
}

通常、あるビューに別のビューから何かを実行するように指示しようとしている場合、代理人はあなたの友達です。delegate却下されるViewControllerへの参照を保持するための弱い変数を作成し、[delegate dismissModalViewControllerAnimated:NO];

于 2012-05-26T23:55:45.853 に答える
1

firstViewControllerのviewDidLoadに通知を登録できます

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"MyNotification" object:nil];

firstViewControllerにイベントハンドラーを追加します

- (void)handleNotification:(NSNotification*)note {
    [self dismissModalViewControllerAnimated:NO];
}

次に、secondViewControllerでイベントをトリガーできます

[[NSNotificationCenter defaultCenter] postNotificationName:@"MyNotification" object:nil ];
于 2012-05-26T23:34:34.113 に答える