【问题标题】:Adding checkbox to IOS 6 AlertView将复选框添加到 IOS 6 AlertView
【发布时间】: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


【解决方案1】:

6之前的iOS版本和7不一样,可以看这个页面custom alter view

最好的解决方案是使用名为custom alter的库

【讨论】:

    猜你喜欢
    • 2017-05-22
    • 1970-01-01
    • 2016-07-17
    • 2017-02-07
    • 2015-11-22
    • 2015-08-13
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多