【发布时间】:2014-10-16 08:46:57
【问题描述】:
我想将复选框视图添加到我的 UIAlertView。 我已经制作了将放置按钮的视图:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 50)];
[buttonCheck setImage:[UIImage imageNamed:@"btn_check_off_holo_light.png"] forState:UIControlStateNormal];
[buttonCheck addTarget:self action:@selector(agreementCheck) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:buttonCheck];
然后我调用 UIAlertview
UIAlertView *alertSeat = [[UIAlertView alloc] initWithTitle:[language stringForKey:@"WARNING_SEAT_TITLE"] message:[NSString stringWithFormat:@"%@\n%@\n\n%@", [language stringForKey:@"WARNING_SEAT_SELECTION"], [language stringForKey:@"WARNING_SEAT_SELECTION2"], [language stringForKey:@"WARNING_SEAT_CONTENT_MESSAGE"]] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertSeat setValue:view forKey:@"accessoryView"];
[alertSeat show];
这在 7.0 及更高版本的 IOS 上运行良好,但在 IOS 6.1 及更低版本上出现以下错误:
*** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]: this 类与键附件视图的键值编码不兼容。'
已尝试在 Google 中搜索,但找不到解决方案。 任何帮助,将不胜感激。谢谢
【问题讨论】:
-
UIAlertViews 应该按原样使用,您不应该弄乱视图层次结构。 -
检查插座和ibactions连接是否正确
-
@Popeye :所以基本上你是说在 alertview 中添加一个视图违反了它的目的,只显示警报弹出通知?
-
无论出于何种原因,Apple 都会限制您可以使用
UIAlertView执行的操作,并且文档中有一条说明指出UIAlertView不能被子类化,您不应该混淆视图层次结构,它应该按原样使用。违反此规定将使您的应用被应用商店拒绝。这使得Light Yagami建议对其进行子类化是非常错误的。然而,有很多第三方库可供使用。
标签: ios objective-c uiview uialertview