2013-06-25 67 views
1
-(void)loginPerform 
{ 
    NSLog(@"start to perform segue!"); 
    [self performSegueWithIdentifier:@"SecondPage" sender:self]; 
    NSLog(@"end perform login!"); 
} 

loginPerform函数在回调函数中调用,并且两个日志都可以打印,因此performSegueWithIdentifier会执行。但当前视图不会更改。performSegueWithIdentifier不起作用回调函数?

  1. view A和view B由Custom Segue关联。
  2. 视图嵌入导航控制器。

顺便说一句:我把测试按钮直接执行segue,它的工作原理。 当loginPerform函数被调用时,下一个视图总是查看A时点击测试按钮。

我不明白whatnd.anybody可以帮助我吗?

int user_account_delegate(int reqid, char* msg) 
{ 
    NSLog(@"DEBUG: login return %s", msg); 
    int reterr = 0; 

    if(reqid!=[BLSInstLink getLoginID]) 
     return -1; 

    /* parse the login result (JSON) */ 
    if(get_json_object_value(msg, KEY_ERROR, VAL_INTEGER, (void*)&reterr)==0) 
    { 
     if(reterr==0) 
     { 
      NSLog(@"DEBUG: login succeed."); 
      [BLSInstLink setLogined:YES]; 
      BLSViewController *this = THIS; 
      [this loginPerform]; 
     } 
     else 
     { 
      NSLog(@"DEBUG: login failed. err=%d", reterr); 
      [BLSInstLink setLogined:NO]; 
      [BLSInstLink setErrorCode:reterr]; 
     } 
    } 
    [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_LOGINRESULT object:nil]; 
    return 0; 
} 

这是我在自己的UIViewController中实现的回调函数。

-(void)loginPerform{ 
    NSLog(@"in loginPerform");//1 
    [self dismissViewControllerAnimated:YES completion:^() { 
     NSLog(@"start perform page2");//2 
     [self performSegueWithIdentifier:@"SecondPage" sender:self]; 
     NSLog(@"end perform page2");//3 
    }]; 
} 

这是称为在回调function.Just 1个打印

- (IBAction)test_click:(id)sender { 
[self performSegueWithIdentifier:@"SecondPage" sender:self]; 
} 

这是一个测试按钮,测试执行赛格瑞的执行功能。它运作良好。

+0

你在写什么类的代码。 UIViewController子类?你能否用更多的代码来阐述你的问题。 – Divyu

+0

检查您的segue标识符名称。它是一样的吗? – Rox

+0

调用的回调是什么线程? – Wain

回答

0

由于它是一个自定义的原因请看它不会推动第二视图automatically.You需要实现你的类prepareForSegue功能与此类似:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
    { 
     if ([segue.identifier isEqualToString:@"SecondPage"]) 
     {  
      secondViewController = [segue destinationViewController]; 
      //add second view as subview of first view. 
     } 
    } 
+0

Thx。我尝试了你的方式,但似乎在视图A的dismissViewControllerAnimated中存在问题。所以[self performSegueWithIdentifier:@“My Segue”sender:self];不会跑。 – user2518788

4

您需要等到其他视图控制器做动画,在执行赛格之前。您可以使用新的iOS 5方法:

[self dismissViewControllerAnimated:YES completion:^() { 
    [self performSegueWithIdentifier:@"My Segue" sender:self]; 
}]; 

如果你需要预先iOS 5的方式做到这一点,你应该只添加一个延迟执行SEGUE之前给动画时间。

否则你可以去这里iOS delegate not working with performSegueWithIdentifier?