2012-07-14 2 views
1

iOS 응용 프로그램을 만들고 점수가 100에 도달하면이 경고가 표시되고 모두 제대로 작동하지만 버튼 (공유, 사과,이 앱의 등급 지정)이 작동합니다. 나는 등 링크를 추가 할 위치에 상관 싶은 것이알림보기 버튼

 - (void) buttonAction { 
       counter++; 
       if(counter == 100) 
        [self showAlert]; 
      } 

      - (void) showAlert { 

       UIAlertView *alert = [[UIAlertView alloc] 

             initWithTitle:@"hello" 
             message:@"whats you name" 
             delegate:nil 
             cancelButtonTitle:@"Dismiss" 
             otherButtonTitles:@"share", @"apple" , @"rate this app", nil]; 


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
     if (buttonIndex == 0) { // means share button pressed 
      // write your code here to do whatever you want to do once the share button is pressed 
     } 
     if(buttonIndex == 1) { // means apple button pressed 
      // write your code here to do whatever you want to do once the apple button is pressed 
     } 
     // and so on for the last button 
    } 

       [alert show]; 



      } 

      -(IBAction)plus { 
       counter=counter + 1; 
       count.text = [NSString stringWithFormat:@"%i",counter]; 
       if(counter == 100) 
        [self showAlert]; 

      } 

      -(IBAction)zero { 
       counter=0; 
       count.text = [NSString stringWithFormat:@"%i",counter]; 
      } 



     - (void)viewDidLoad { 
      counter=0; 
      count.text = @"0"; 
       [super viewDidLoad]; 

     } 

UIAlertView *alert = [[UIAlertView alloc] 

         initWithTitle:@"hello" 
         message:@"whats you name" 
         delegate:self 
         cancelButtonTitle:@"Dismiss" 
         otherButtonTitles:@"share", @"apple" , @"rate this app", nil]; 

[alert show]; 

다음 코드에서 다음과 같은 방법을 추가 ... 당신이

+0

나는 당신이 원하는 것을 이해하지 못합니다. –

+0

@PrasadG 버튼을 어떻게 만들 수 있는지에 대한 실제적인 방법 (예 : 사과 등 사과 사이트로 이동). – Picm

답변

11

다음을 시도 감사 :

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
     if (buttonIndex == 0) { // means share button pressed 
       // write your code here to do whatever you want to do once the share button is pressed 
     } 
     if(buttonIndex == 1) { // means apple button pressed 
       // write your code here to do whatever you want to do once the apple button is pressed 
     } 
     // and so on for the last button 
} 

자문을 구하십시오. 질문에서 명확한 점이 있다면 당신은

내가, 당신이 사용자에 의해 누를 때 경고하는 버튼을 식별하는 방법이 필요하다는 것을 이해는 당신의 질문에서

+0

방금 ​​추가 했으므로 다음 오류가 발생합니다. 신고되지 않은 식별자 'alertView'를 사용하셨습니까? UIAlertView? 그리고 조언을 주셔서 감사 드리며 마음 속에서 계속 지키고 http://www.apple.com을 추가하면 – Picm

+0

고맙습니다. 내 코드를 올려 놓은 곳에서 내 대답을 편집했습니다 – Picm

+0

내가 편집했습니다. 지금 코드가 작동해야합니다 ... 내 대답을 올바르게 표시하면 자유롭게 답변 할 수 있습니다.) –

0

도움이되기를 바랍니다 ...하고 싶어. 이를 위해 위임 메서드를 사용할 수 있습니다.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 

} 

이 메서드의 내부에서 사용자가 누른 단추 인덱스를 확인해야합니다. 그리고 그것에 따르면, 당신은 다른 것들을 할 수 있습니다.

대리자 방법을 사용하기 위해, 당신은 더 참고 self

에 경고보기의 delegate을 설정해야합니다 – alertView:didDismissWithButtonIndex: : http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.html

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html#//apple_ref/doc/uid/TP40007548

0

당신은 UIAlertViewDelegate 방법을 구현해야 초기화 할 때 컨트롤러를 UIAlertViewDelegate로 설정 한 다음 – alertView:didDismissWithButtonIndex: 구현 내에서 다양한 메소드 호출 관련 버튼 인덱스로 이동합니다.