2014-05-09 7 views
0

경고보기 .tag를 사용하여 일부 방법을 읽었지만 작동하지 않습니다.하나의보기 컨트롤러에서 여러 경고보기 (태그가 작동하지 않음)

첫 번째 경고 :

-(void)addNewTask 
{ 

    UIAlertView * alert1 = [[UIAlertView alloc] initWithTitle:@"New Task" 
    message:nil  
    delegate:self 
    cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; 
    alert1.alertViewStyle = UIAlertViewStylePlainTextInput; 
    [alert1 show]; 
} 

두 번째 경고

-(void)changeTime:(int)value atRow:(int)p 
{ 

    TaskData *data = [tasks objectAtIndex:p]; 

    NSLog([NSString stringWithFormat:@"%d %d",data.time,value]); 


    int time = data.time ; 

    time += value; 

    data.time = time; 

    NSLog([NSString stringWithFormat:@"%d %d",data.time,value]); 



[self saveData:tasks]; 

[self.Taskview reloadData]; 

if(time>=5&&(data.leveljudge!=1)) 
{ 
    UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Congratulation!!!" 
    message:@"You have achieve Senior Level. " 
    delegate:nil 
    cancelButtonTitle:@"Cancel" otherButtonTitles:@"YES",nil]; 



    data.leveljudge=1; 
    [alert2 show]; 

} 

대표 :

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
NSString *name = [alertView buttonTitleAtIndex:buttonIndex]; 

if ([name isEqualToString:@"OK"]) 
{ 
    UITextField *tf=[alertView textFieldAtIndex:0]; 

    NSString *name = tf.text; 
    TaskData *newTask = [[TaskData alloc] init]; 
    newTask.TaskName = name; 
    newTask.time = 0; 
    newTask.leveljudge=0; 
    [tasks addObject:newTask]; 

    [self saveData:tasks]; 

    [self.Taskview reloadData]; 

} 

else if ([name isEqualToString:@"YES"]) { 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://d.blog.xuite.net/d/1/5/4/12103250/blog_1606564/txt/53796893/2.jpg"]];   
} 
} 

문제 대리인은 첫 번째 경고에만 작동합니다. 당신이 대리자를 설정하지 않았기 때문에 alert2를 들어 https://www.youtube.com/watch?v=WxlVKk0CTiQ

+3

두 번째 경고 대리인을 설정하지 않습니다. UIAlertView * alert2 = [[UIAlertView alloc] initWithTitle : @ "축하합니다 !!!" message : @ "당신은 고위급을 달성했습니다." ** 대리인 ​​: nil ** cancelButton 제목 : @ "취소"otherButtonTitles : @ "예", nil]; 천막 대표자 : 자아. 대의원이 동참 할 것입니다. – Savitha

+1

'tag '를 사용하면 효과가 있습니다. 태그 사용 시도는 어디에서합니까? – rmaddy

답변

0

, 위임가 호출되지 : 내 애플처럼 보인다.

다음과 같이 변경해보십시오.

는 Alert1

UIAlertView * alert1 = [[UIAlertView alloc] initWithTitle:@"New Task" 
                message:nil  
               delegate:self 
         cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; 
alert1.alertViewStyle = UIAlertViewStylePlainTextInput; 
alert1.tag = 101; //Add a Tag to the alert 

[alert1 show]; 

Alert2 경보 2 위임 제대로

UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Congratulation!!!" 
          message:@"You have achieve Senior Level. " 
          delegate:self //Set your delegate 
cancelButtonTitle:@"Cancel" otherButtonTitles:@"YES",nil]; 


alert2.tag = 102; //Add a different tag value to the second alert 
data.leveljudge=1; 
[alert2 show]; 

위임

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if(alertView.tag == 101) 
    { 
     //Handle Alert 1 
    } 
    else if(alertView.tag ==102) 
    { 
     //Handle Alert 2 
    } 
} 
+0

감사합니다. 그것은 효과가있다. 나는 어리석은 실수를 저질렀다. – user3619032

1
-(IBAction)flipAction:(id)sender 
{ 
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"This is My Button" message:@" Hi" delegate:self cancelButtonTitle:@"OK " otherButtonTitles:@"Cancel", nil]; 
    alert.tag=1; 
    [alert show]; 
    [alert release]; 
} 

-(IBAction)flipAction123:(id)sender 
{ 
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"This is a flipAction123" message:@"this is message..." delegate:self cancelButtonTitle:@"OK " otherButtonTitles:@"Cancel", nil]; 
    alert.tag=2; 
    [alert show]; 
    [alert release]; 

} 



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

{ 
    if (alertView.tag==1) 
    { 
     if (buttonIndex==0) 
     { 
      UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"This is another alert button" message:@"" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; 
      [alert show]; 
      [alert release]; 
     } 
     else 
     { 
      NSLog(@"paresh here.."); 
     } 

    } 
    else if(alertView.tag==2) 
    { 
     UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"This is another alert alertView.tag ==2" message:@"" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; 
     [alert show]; 
     [alert release]; 
    } 
    } 
0
설정되지
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Congratulation!!!" 
    message:@"You have achieve Senior Level. " 
    delegate:self //here should be self, not nil 
    cancelButtonTitle:@"Cancel" otherButtonTitles:@"YES",nil]; 
data.leveljudge=1; 
[alert2 show]; 
+0

고맙습니다. 지금은 이해. – user3619032

관련 문제