我想在点击单元格时显示警报 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/