I have a very tricky situation. And all things I have did programmatically.
1) I have UITableView.
2) In every cell of this tableview I have one uibutton.
3) On click of UIButton
I want to show a UIAlertView
, Which have yes and not buttons.
4) On click of yes button I want to delete that cell whose UIButton
had shown up this alertview.
Below is my code snippet:
- (void) removeFriends:(id)sender
{
/*
I want to show alertview at 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 to make call to server
}
}
}