Reputation:
I have a tableview of items and when i click one row, I want to use uialertview with uiactionsheet with button: edit, remove and cancel. When I click button edit, I will open a modal view. Before, I did edit modal view already and when I click one row, I will go to edit modal view, but now I want to add uiactionsheet, so how can I do this ?
Upvotes: 0
Views: 1144
Reputation: 6718
Write UIAlertview or UIActionsheet in -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
method.
I think it will be helpful to you.
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"title" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"delete" otherButtonTitles:@"other 1", @"other 2", nil];
[actionSheet showInView:self.view];
//or
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"button",@"button1", nil];
[alert show];
}
Upvotes: 1
Reputation: 1818
Just use a UIAlertView as follows:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Edit", @"Remove", nil];
[alert show];
The following method will check which button is pressed:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
switch (buttonIndex)
{
case 1:
// perform Edit
break;
case 2:
// perform Remove
break;
case 0:
// perform Cancel, if any
break;
}
}
Upvotes: 0