ios - 如何通过单击 uitableViewCell(Objective-c) 获取警报 View

标签 ios tableview uialertcontroller

我想在点击单元格时显示警报 View

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}

一个最简单的方法就够了,谢谢。

最佳答案

简单来说,您可以根据单击的单元格显示警报 View 。所以

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0) { //Change 0 to the row you want 
        [self showAlertView];
    }
}

然后在一个单独的函数中

-(void)showAlertView {
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"YOUR TITLE"
                                                                         message:@"AND A MESSAGE OF YOUR ALERT"
                                                                         preferredStyle:UIAlertControllerStyleAlert];
     //We add buttons to the alert controller by creating UIAlertActions:
     UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"YOUR BUTTON TITLE"
                                                   style:UIAlertActionStyleDefault
                                                 handler:nil]; //You can use a block here to handle a press on this button
     [alertController addAction:actionOk];
     [self presentViewController:alertController animated:YES completion:nil];
}

编辑*********

根据您的评论

如果您想根据单元格标识符显示警报,那么您可以在 didSelectRowAtIndexPath 方法中使用类似的内容。

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

if([cell.reuseIdentifier isEqualToString:@"CELLIDENTIFIER"]){
    [self showAlertView];
}

关于ios - 如何通过单击 uitableViewCell(Objective-c) 获取警报 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35155645/

相关文章:

tableview - 如何禁用 tableView 中表列的重新排序?

ios - 如何在 Realm 数组的特定索引处插入对象?

带有自定义控件的 JavaFX8 TableView

ios - Swift UIAlertController,文本中带有 url

android - Xamarin Forms 跨平台 BBCode 支持

ios - UIProgressView 自定义最大值

ios - 更新后 RealmSwift 崩溃并出现错误 "Invalid property name"

ios - cocoa touch : How To Change UIView's Border Color And Thickness?

swift - 在操作表中显示多个图像

ios - dismissViewControllerAnimated 在 block 内不起作用