0

pop/pushViewControllersを使用してviewControllersをリダイレクトする際に問題が発生しています。私は下の画像のような3つのビューコントローラーを持っています-

制御フロー

私の3番目のビューでは、2番目のビューにあるデータが変更されることにToggleButton基づいていtoggleButtonます。その後、3番目のビューで何かを変更しDone、3番目のビューでボタンを押すと、Andを使用して2番目のViewControllerを起動しpushViewControllerました。変更は正常に行われます。

しかし、問題は、2番目のビューページで戻るボタンを押そうとすると、3番目のviewControllerに再度リダイレクトされることです(pushViewControllerのため)

を使用して2番目のビューを開始しようとしましpopViewControllerたが、例外があります。

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.

私は以下のコードを使用しました-

SecondViewController *second = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
second.array = resultArray;
second.indexValue = ind;
[self.navigationController popToViewController:second animated:YES];

この問題を解決するにはどうすればよいですか?何か案が?

4

4 に答える 4

1

3番目のviewcontrollerから、このメソッドを呼び出して2番目のviewcontrollerにポップする必要があります。

[self.navigationController popViewControllerAnimated:YES];

編集 :

データ変更について2番目のVCに通知するには、デリゲートを使用できます。これに従ってください:

ThirdViewController.hで

@protocol DataChangeProtocol;
@interface ThirdViewController : UIViewController

@property(nonatomic,assign) id<DataChangeProtocol> delegate;

@end


@protocol DataChangeProtocol

- (void)thirdViewcontroller:(ThirdViewController*)vc dataChangedto:(NSDictionary *)changedData;

@end

そして、secondVCからthridVCをプッシュする前に、secondVCをthirdVCのデリゲートとして割り当てます。

ThirdViewController *thirdVC = [[ThirdViewController alloc]init..];
thirdVC.delegate = self;
[self.navigationController pushViewController:thirdVC animated:YES];

およびSecondViewController.m

- (void)thirdViewcontroller:(ThirdViewController*)vc dataChangedto:(NSDictionary *)changedData {
 // Change your values in the UI using the passed value from changedData.

}
于 2012-10-29T09:40:55.010 に答える
1

現在の以前のViewControllerに移動する場合は、次のことを行う必要があります。

[self.navigationController popViewControllerAnimated:YES];
于 2012-10-29T09:42:19.503 に答える
1

ビューコントローラを作成します。

SecondViewController *second = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

次に、スタックからポップしたいのですが、このコントローラーはスタックにありません。これは、3番目のviewControllerで作成したためです。

于 2012-10-29T09:43:14.663 に答える
1
    //it used in first class
     SecondViewController *second = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
second.array = resultArray;
second.indexValue = ind;
    [self.navigationController pushViewController:second animated:YES];
    //it move to second class

    //it used in second class
    [self.navigationController popViewControllerAnimated:YES];
    //it move to firsr class
于 2012-10-29T09:58:42.257 に答える