0
我想表明的点击细胞如何获得通过单击tableViewCell(Objective-C的)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
一个简单的方法是不够的,由于警报视图AlertView。
我想表明的点击细胞如何获得通过单击tableViewCell(Objective-C的)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
一个简单的方法是不够的,由于警报视图AlertView。
简而言之,您可以基于单击单元格显示警报视图。所以
-(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];
}
编辑*********
基于您的评论
如果你想显示警报基于在cell标识符上,你可以在didSelectRowAtIndexPath方法中使用类似这样的东西。
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if([cell.reuseIdentifier isEqualToString:@"CELLIDENTIFIER"]){
[self showAlertView];
}
感谢你的帮助,首先,但我想知道如果我想使用标识的方式来显示当我点击特定小区的alertView什么,比如我单击单元格的标识是“showAlertView”?谢谢再次。 –
,完美的作品,thx –
没问题。如果你的需要你可以接受这个答案作为解决方案。谢谢 – Devster101