alertView的一些建议

对tableviewcontroller大家一般会有如下代码

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

    NSUInteger row = indexPath.row;

    NSString *rowValue = [listData objectAtIndex:row];

    

    NSString *msg = [[NSString alloc]initWithFormat:@"You selected %@", rowValue];

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Row Slected" message:msg delegate:nil cancelButtonTitle:@"Yep, I did" otherButtonTitles: nil];

    

    [msg release];

    [alert show];

    [alert release];

    [tableView deselectRowAtIndexPath:indexPath animated:YES];//在弹出警告后自动取消选中表视图单元

}

但是在设计相应按钮时间时候会有如下代码

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    

    switch (buttonIndex) {

        case 0:

            NSLog(@"Cancel Button Pressed\n");

            break;

        case 1:

            NSLog(@"change Pressed\n");

            break;

        case 2:

            NSLog(@"Button 2 Pressed\n");

            break;

        case 3:

            NSLog(@"Button 3 Pressed\n");

            break;

        default:

            NSLog(@"-1\n");

            break;

    }

    

}

同时各路大神还会建议加上委托UIAlertViewDelegate,无论你继承自UIViewController还是UITableViewController都可以,反正

UITableViewController是UIViewController的子类,但是要注意

  UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Row Slected" message:msg delegate:nil cancelButtonTitle:@"Yep, I did" otherButtonTitlesnil];

把delegate:nil 改为delegate:self(很多入门教程都采用的前者)

不然会无法响应响应时间,因为alert不知道委托在是谁,虽然你加了委托UIAlertViewDelegate

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值