如何在tableview中使用uialert和uiactionsheet

时间:2012-08-21 06:51:20

标签: iphone ios uialertview uiactionsheet

我有一个项目的tableview,当我点击一行时,我想使用带有按钮的uiactionsrt的uialertview:编辑,删除和取消。当我点击按钮编辑时,我将打开一个模态视图。以前,我已经编辑了模态视图,当我点击一行时,我会去编辑模态视图,但现在我想添加uiactionsheet,那么我该怎么做呢?

2 个答案:

答案 0 :(得分:1)

使用-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath方法编写UIAlertview或UIActionsheet。

我认为这会对你有所帮助。

-(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];

}

答案 1 :(得分:0)

只需按如下方式使用UIAlertView:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Edit", @"Remove", nil];
[alert show];

以下方法将检查按下的按钮:

- (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;
    }
}
相关问题