在h.文件中已经写有UIAlertViewDelegate,m.文件中delegate:self的
为什么点击@"Cancel"、@"Delete"、@"Add"都是没有响应呢?小白不懂,求大神解答。。
h.文件
@interface tableViewController : UITableViewController {
NSMutableArray *a;
}
m.文件
// 创建警告视图
UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"编辑" message:@"请选择条目" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", @"Add", nil];
// 显示警告视图
[al show];
UIAlertView (警告视图)这个控件的应用领域非常广泛,是一个很实用的控件。
创建代码如下: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"标题" message:@"提示文本信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定1",@......
答案就在这里:iOS-UIAlertView的点击事件
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
你要重写代理方法啊!
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// 获取当前点击的按钮标题
NSString *titileString = [alertView buttonTitleAtIndex:buttonIndex];
// 判断是否选择了Delete按钮
if ([titileString isEqualToString:@"Delete"]) {
// 设置为可编辑
[self setEditing:YES];
}
// 判断是否选择了Add按钮
if ([titileString isEqualToString:@"Add"]) {
UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"添加" message:@"确定要添加联系人吗?" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
// 显示提示框
[al show];
}
打个断点跟一下,看看走没走代理
是点击按钮后alertView不会自动消失?还是没有收到事件回调?
如果是没有收到回调,那看看是不是delegate对象被释放了,也就是你的 tableViewController
是不是已经没有被引用,已经释放掉了
// 显示警告视图
[al show];
这里显示警告,看看你是不是有个全局的变量 al 啊 !如果是的话 有可能 就不会走 你代理方法里面的判断条件了。。
看看有没有实现下述方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {}
看看有没有实现下述方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {}