2013-10-19 4 views
0

그래서 ACAccountStore를 사용하여 로그인/가입하려고합니다. 이것은 모달로 제공되는보기 컨트롤러를 사용하여 발생합니다. 그런 식으로 잘 작동하지만 뷰 컨트롤러를 닫을 때 기본/제시 컨트롤러는 여전히 검정색 창입니다. 완성 블록이 끝나기를 기다리지 않기 때문에 이런 일이 일어난다 고 가정합니다.XCode - 블록 완료시 코드 실행

내 질문 : [self dismissViewControllerAnimated:YES completion:nil];에 전화하기 전에 완료 블록이 완료 될 때까지 어떻게 기다려야합니까?

-(void)loginWithTwitter{ 

ACAccountStore *account = [[ACAccountStore alloc] init]; 
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier: 
           ACAccountTypeIdentifierTwitter]; 

[account requestAccessToAccountsWithType:accountType options:nil 
           completion:^(BOOL granted, NSError *error) 
{ 
    if (granted) { 
     //do something -> call function to handle the data and dismiss the modal controller. 
    } 
    else{ 
     //fail and put our error message. 
    } 
}]; 
} 
+0

왜 다른 코드 뒤에 삽입 할 수 없습니까? 딜레이가 필요하다면 딜레이 후에 공연 선택기를 사용하지 않는 것이 좋습니다. 그것은 예쁘지 않지만 C'est la vie. –

답변

2

완료 블록이 완성된다 (이 경우 계정 요청에 대한 액세스) 후 메인 프로세스 실행되도록 일이다. 그래서 [self dismissViewControllerAnimated:YES completion:nil]을 넣을 수 있습니다.

또 다른 것 : 유지주기 때문에 블록에 self에 대한 참조가있는 것이 좋지 않습니다. 다음과 같이 코드를 수정하십시오.

ACAccountStore *account = [[ACAccountStore alloc] init]; 
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier: 
     ACAccountTypeIdentifierTwitter]; 

__weak UIViewController *weakSelf = self; 
[account requestAccessToAccountsWithType:accountType options:nil 
           completion:^(BOOL granted, NSError *error) { 
    [weakSelf dismissViewControllerAnimated:YES completion:nil]; 

    if (granted) { 
     //do something -> call function to handle the data and dismiss the modal controller. 
    } 
    else { 
     //fail and put our error message. 
    } 

}]; 
+0

흠. 이것은 "효과가있다"- 그러나 문제를 제거하지는 않습니다. 제시되는 뷰 컨트롤러의 등장 이전에 간단한 "블랙 스크린"이 블럭과 아무 관계가 없다고 믿게한다. – schnabler

+0

기본 뷰 컨트롤러에 문제가 있다고 생각합니다. 검은 화면 대신에 무엇을 기대합니까? – LorikMalorik

+0

꽤 많은 "일반"disMissViewControllerAnimated 동작. ModalView가 아래로 스크롤하면 기본 화면이 나타납니다. 하지만 그래, 실제로 그것은 기본 컨트롤러에 문제가있는 것 같습니다. – schnabler

관련 문제