2014-08-29 4 views
-1

다음 예제를 얻으 려합니다.이 예제는 몇몇 웹 사이트에 표시되지만 작동하지 않는 것 같습니다.다음 UIAlertView 코드가 작동하지 않는 이유는 무엇입니까?

'UIAlertView에 대한 가시적 @ 인터페이스 내가 갖는

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Yes, like this" message:@"What are you looking at?" cancelButtonTitle:@"Leave me alone" otherButtonTitles:@"Button 1",@"Button 2",nil]; 
    [alert showWithDismissHandler:^(NSInteger selectedIndex, BOOL didCancel) { 
     if (didCancel) { 
      NSLog(@"User cancelled"); 
      return; 
     } 
     switch (selectedIndex) { 
      case 1: 
       NSLog(@"1 selected"); 
       break; 
      case 2: 
       NSLog(@"2 selected"); 
       break; 
      default: 
       break; 
     } 
    }]; 

경고는

'UIAlertView '에 대한 눈에 띄는 @ 인터페이스가 선택'메시지 : cancelButtonTitle : otherButtonTitles initWithTitle '을 선언하지 않습니다 '선택기'showWithDismissHandler : '를 선언합니다.'

정말로 정말 사소한 질문이지만, 무엇이 실종 됐습니까?

감사합니다.

답변

4

서명이 올바르지 않습니다. 당신은 대의원을 놓쳤습니다.

– initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles: 

표준 UIAlertView

showWithDismissHandler 방법이 없습니다. 인터넷에서 일부 코드를 복사 한 경우 UIAlertViewblock 콜백을 지원하는 타사 패키지를 다운로드해야 할 수 있습니다 (상당수가 있음).

1

네, 피터가 맞습니다!

– initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles: 

와 당신이 여기 일을하려고하면 alertview is dismissedmethod 당신이 is not available을 사용하는 경우 일을하는 것입니다 : 첫 번째 경고는 서명이 올바르지 않습니다 때문이다. UIAlertViewDelegate을 구현 한 다음이 방법 중 하나를 사용하여 여기서 수행하려는 작업을 수행하십시오.

http://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html

0

당신이 UBAlertView 같은 것을 사용하고, 혹시 :

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex 

여기 UIAlertView의 위임 참조에 대한 링크입니다?

UBAlertView *alert = [[UBAlertView alloc] initWithTitle:@"Yes, like this" 
               message:@"What are you looking at?" 
             cancelButtonTitle:@"Leave me alone" 
             otherButtonTitles:@"Button 1",@"Button 2",nil]; 
[alert showWithDismissHandler:^(NSInteger selectedIndex, BOOL didCancel) { 
    ... etc ... 

(. 나는 긴 방법은 그들을 더 읽을 수 있도록 호출에 줄 바꿈을 넣어 좋아)

: 그렇다면, 당신은 UBAlertView 아닌 UIAlertView를 인스턴스화 할 필요가
관련 문제