ios - get the referance of uitableviewcell on click of a button in uialertview -


i have tricky situation. , things have did programmatically.

1) have uitableview.
2) in every cell of tableview have 1 uibutton.
3) on click of uibutton want show uialertview, have yes , not buttons.
4) on click of yes button want delete cell uibutton had shown alertview.

below code snippet:

- (void) removefriends:(id)sender {     /*       want show alertview @ here...       uialertview *alert = [[uialertview alloc] initwithtitle:nslocalizedstring(@"confirm",nil) message:nslocalizedstring(@"remove_friend",nil)  delegate:self cancelbuttontitle:@"no"  otherbuttontitles:@"yes", nil];       alert.tag = 21;       alert.accessibilityidentifier = @"remove";       [alert show];       */      uibutton *btn = (uibutton*)sender;      int indx = btn.tag;     nsstring *friend_id = [friendsid valueforkey:[nsstring stringwithformat:@"%d",indx]];      // url creation     nsstring *path = [[nsbundle mainbundle] objectforinfodictionarykey:@"path"];      nsstring *address = [nsstring stringwithformat:@"%@%@%@", path,@"users/",usrid];      nsurl *url = [nsurl urlwithstring:address];      // request creation     nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlcachestorageallowedinmemoryonly                                                        timeoutinterval:60.0];     [request sethttpmethod:@"delete"];      responsedata = [[nsmutabledata alloc] init];      nsurlconnection *connection = [[nsurlconnection alloc] initwithrequest:request delegate:self];     [connection start];      uitableviewcell *buttoncell = (uitableviewcell *)[btn superview];     nsindexpath* pathofthecell = [self.table indexpathforcell:buttoncell];      [self.table deleterowsatindexpaths:[nsarray arraywithobjects:pathofthecell, nil] withrowanimation:uitableviewrowanimationfade];     [self viewdidload];     [self.table reloaddata]; }  -(void) alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex {     if([alertview.accessibilityidentifier isequaltostring:@"remove"])     {         if (buttonindex == 1)         {             // here want make call  server         }     } } 

just put this:

nsstring *friend_id = [friendsid valueforkey:[nsstring stringwithformat:@"%d",indx]];   // url creation nsstring *path = [[nsbundle mainbundle] objectforinfodictionarykey:@"path"];  nsstring *address = [nsstring stringwithformat:@"%@%@%@", path,@"users/",usrid];  nsurl *url = [nsurl urlwithstring:address];  nslog(@"%@",address);  // request creation nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlcachestorageallowedinmemoryonly                                                    timeoutinterval:60.0];  [request sethttpmethod:@"delete"];  responsedata = [[nsmutabledata alloc] init];  nsurlconnection *connection = [[nsurlconnection alloc] initwithrequest:request delegate:self]; [connection start];  uitableviewcell *buttoncell = (uitableviewcell *)[btn superview]; nsindexpath* pathofthecell = [self.table indexpathforcell:buttoncell];  [self.table deleterowsatindexpaths:[nsarray arraywithobjects:pathofthecell, nil] withrowanimation:uitableviewrowanimationfade]; [self viewdidload]; [self.table reloaddata]; 

into this:

if([alertview.accessibilityidentifier isequaltostring:@"remove"]){     if (buttonindex == 1) {         // here want make call  server      } } 

and create property in .h file holding id of button had been pressed. this:

//in .h file @property (nonatomic, strong) nsstring *yourid; 

and in button-action set this:

self.yourid = [friendsid valueforkey:[nsstring stringwithformat:@"%d",indx]]; 

in first code snippet guess have replace usrid self.yourid,

nsstring *address = [nsstring stringwithformat:@"%@%@%@", path,@"users/",self.yourid]; 

edit: remove this:

uitableviewcell *buttoncell = (uitableviewcell *)[btn superview]; 

and change this:

nsindexpath* pathofthecell = [self.table indexpathforcell:buttoncell]; 

to this:

nsindexpath* pathofthecell = [nsindexpath indexpathforrow:self.yourid] 

self.yourid indexpath.row value saved in button.tag property.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -