0

我在使用 pop/pushViewControllers 重定向 viewControllers 时遇到问题。我有三个视图控制器,如下图 -

控制流

在我的第三个视图中,我有一些ToggleButton基于toggleButton第二个视图中的数据会改变。之后,在第三个视图上更改某些内容并Done在我的第三个视图中按下按钮,我刚刚使用pushViewControllerAnd 启动了我的第二个 ViewController,更改成功发生。

但是,问题是,当我尝试按下第二个视图页面上的后退按钮时,它再次将我重定向到第三个 viewController(因为 pushViewController)

我尝试使用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

从 3rd viewcontroller 你只需要调用这个方法来弹出到 2nd viewcontroller :

[self.navigationController popViewControllerAnimated:YES];

编辑 :

要通知第二个 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
    //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 回答
1

如果你想去你当前的前一个视图控制器,那么你必须这样做:

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

您创建我们的视图控制器:

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

然后你想从你的堆栈中弹出它但是这个控制器不在堆栈中,因为你在第三个 viewController 中创建了它。

于 2012-10-29T09:43:14.663 回答