objective c - ActionSheet clickedButtonAtIndex being used by 2 different actions -
currently following delegate listens selectedindex works takes action on index not belong action.
action1:
- (ibaction)sendpicture:(id)sender {  uiactionsheet *popupquery = [[uiactionsheet alloc] initwithtitle:nil                                                         delegate:self cancelbuttontitle:@"cancel"                                           destructivebuttontitle:nil                                                otherbuttontitles:@"take photo",@"choose existing photo",nil];  popupquery.actionsheetstyle = uiactionsheetstyleblackopaque; [popupquery showinview:self.view];   }   action2:
- (ibaction)sendtip:(id)sender {   uiactionsheet *popupquery = [[uiactionsheet alloc] initwithtitle:@"how want tip?"                                                         delegate:self cancelbuttontitle:@"cancel"                                           destructivebuttontitle:nil                                                otherbuttontitles:@"5.00 $",@"10.00 $",@"15.00 $",@"25.00 $",@"50.00 $",nil];  popupquery.actionsheetstyle = uiactionsheetstyleblackopaque; [popupquery showinview:self.view];  }   delegate listens selectedindex of both actionsheet menues:
-(void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex {
nslog(@"selected index: %d",buttonindex);  if (buttonindex == 0) {      urltip = [nsstring stringwithformat:@"http://api.site.ca/user-tip/%@/%@/%@/",_http_nickfrom, _http_nickto, @"1"];       uialertview *alertview = [[uialertview alloc] initwithtitle:@"confirmation"                                                         message:@"do want send 5.00 $?"                                                        delegate:self                                               cancelbuttontitle:@"cancel"                                               otherbuttontitles:@"send", nil];     [alertview show];   } if (buttonindex ==1){      urltip = [nsstring stringwithformat:@"http://api.site.ca/user-tip/%@/%@/%@/",_http_nickfrom, _http_nickto, @"2"];      uialertview *alertview = [[uialertview alloc] initwithtitle:@"confirmation"                                                         message:@"do want send 10.00 $?"                                                        delegate:self                                               cancelbuttontitle:@"cancel"                                               otherbuttontitles:@"send", nil];     [alertview show];  }  if(buttonindex == 2){      urltip = [nsstring stringwithformat:@"http://api.site.ca/user-tip/%@/%@/%@/",_http_nickfrom, _http_nickto, @"3"];      uialertview *alertview = [[uialertview alloc] initwithtitle:@"confirmation"                                                         message:@"do want send 15.00 $?"                                                        delegate:self                                               cancelbuttontitle:@"cancel"                                               otherbuttontitles:@"send", nil];     [alertview show];  }  if(buttonindex == 3){     urltip = [nsstring stringwithformat:@"http://api.site.ca/user-tip/%@/%@/%@/",_http_nickfrom, _http_nickto, @"4"];      uialertview *alertview = [[uialertview alloc] initwithtitle:@"confirmation"                                                         message:@"do want send 25.00 $?"                                                        delegate:self                                               cancelbuttontitle:@"cancel"                                               otherbuttontitles:@"send", nil];     [alertview show];  }  if(buttonindex == 4){      urltip = [nsstring stringwithformat:@"http://api.site.ca/user-tip/%@/%@/%@/",_http_nickfrom, _http_nickto, @"5"];      uialertview *alertview = [[uialertview alloc] initwithtitle:@"confirmation"                                                         message:@"do want send 50.00 $?"                                                        delegate:self                                               cancelbuttontitle:@"cancel"                                               otherbuttontitles:@"send", nil];     [alertview show];  }     }   i want able take values of sendpicture , perform actions instead of executing index belongs other action.
there few ways this. easiest way:
- save both of uiactionsheets class's properties, saved 
photoactionsheet,tipactionsheet. in following delegate method
-(void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindexcompare actionsheet like:
if (actionsheet == self.photoactionsheet){ //do }
the second way have class implement delegate method. recommend easier way, depends on how structure project.
Comments
Post a Comment