2013-07-20 4 views
0

사용자가 경고가있는 단추를 클릭 할 때 팝업을 표시하려고 시도하고 취소를 클릭하면 해제되지만 계속을 클릭하면 뷰 컨트롤러를 제시하고 싶습니다. 여기에 내 코드가 있지만 버튼을 누를 때마다 팝업이 닫히기 만합니다.팝업 코드에 반응하는 코드에 어떤 문제가 있습니까?

- (IBAction)latest:(id)sender { 
    alert = [[UIAlertView alloc] initWithTitle:@"WARNING" message:@"Continuing will use internet and may cause app to slow down in large crowds" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil]; 
    [alert show]; 
} 

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if (buttonIndex == 2) { 
     UIViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@"Latest"]; 
     [self presentViewController:NVC animated:YES completion:Nil]; 
    } 
} 
+0

감사합니다. – user2578110

답변

0

if (buttonIndex == 1)에 변경하지 시작 - 당신이 경고보기의 위임하지 nilself을 통과해야합니다.

또한 대리자 메서드에서 단추 인덱스를 하드 코딩하지 마십시오. 대신 다음을 수행하십시오.

if (buttonIndex == alertView.firstOtherButtonIndex) { 
} 
0

두 가지 옵션 만 선택할 수 있습니다. 인덱스는 0에서 1 그래서 if (buttonIndex == 2) 당신의 문제는 간단하다

+0

나는 그것을 1과 0으로 바꿨지 만 어느 것도 효과가 없었습니다 – user2578110

+0

조금 놀아서 5 분 만에 돌아 왔습니다. – Arbitur

+0

NSLog (@ "Called")를 추가하십시오; 함수가 호출되는 경우 se를 반환합니다. – Arbitur

0

Ok 알아 두었습니다. 나는 위임자를 자기 자신으로 설정해야했고, 그것은 "무효"로 설정되었다.

관련 문제