ios7 - 如何过渡到自我

时间:2014-09-16 10:39:36

标签: ios7

根据以下故事板,我有一个RootViewController(嵌入在TabBarController中),它使用垂直菜单管理许多ViewControllers。

当这个RootViewController加载时,我检查客户端身份验证,如果尚未验证,我切换到ConnectViewController进行远程身份验证

@implementation WDURootViewController
....
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     if (!self.client.isAuthorized) {
         WDUConnectViewController *cvc = self.connectVC;
         [self addChildViewController:cvc];
         [self.view addSubview:cvc.view];
         [cvc didMoveToParentViewController:self];
      }
}

验证成功后,我想回到RootViewController ...... 所以在我的ConnectViewController中,我回调一个didConnect()方法来通知RootViewController

@implementation WDUConnectViewController
....
- (IBAction)sendGrantRequest
{
....
 [self.client authorizeUser:login password:pwd
       onSuccess:^() {
           [self.workinOnIt stopAnimating];
           [self.connectButton setEnabled:YES];
           [(WDURootViewController *)self.parentViewController didConnect];
        }

并在RootViewController中,didConnect()方法我尝试切换视图,从ConnectViewController转换到RootViewController

@implementation WDURootViewController
....
- (void)didConnect
{
    [self transitionFrom:self.connectVC To:self];
}
....
        - (void)transitionFrom:(UIViewController *)oldC To:(UIViewController *)newC
    {
        [oldC willMoveToParentViewController:nil];
        [self addChildViewController:newC];
        [self transitionFromViewController: oldC toViewController: newC
                              duration: 0.25 options:0
                            animations: nil
                            completion:^(BOOL finished) {
                                [oldC removeFromParentViewController];
                                [newC didMoveToParentViewController:self];
                            }];
    }

    - (WDUConnectViewController *)connectVC {
        if (_connectVC == nil) {
            UIStoryboard *storyboard = self.storyboard;
            _connectVC = [storyboard instantiateViewControllerWithIdentifier:@"WDUConnectViewController"];
            _connectVC.client = self.client;
        }
        return _connectVC;
    }

但是过渡方法正在循环......我想这不是最好的方式,最简单的方法是什么?

1 个答案:

答案 0 :(得分:0)

我知道了,只是更新了RootViewController中的didConnect()方法

- (void)didConnect
{
    [self.connectVC willMoveToParentViewController:nil];
    [self.connectVC.view removeFromSuperview];
    [self.connectVC removeFromParentViewController];
    [self awakeFromNib];
}