ios - 将自定义 View 添加到警报 View

标签 ios uialertview xib addsubview sdcalertview

我有这样的问题:

我想在警报 View 中显示自定义 View 。所以我创建了一个单独的 xib 文件并设计了我的界面。也为它实现了类。但是当我应用下面的代码时,它给了我一个错误。

这是代码:

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm your Action"
                                                    message:@"Click OK to confirm"
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:@"Cancel",nil];


    NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"customDialogViewController"  owner:self options:nil];
    customDialogViewController *myView = (customDialogViewController*) [subviewArray objectAtIndex:0];

    [alert setValue:myView forKey:@"accessoryView"];
    //alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    alert.tag = KAlertViewthree;
    [alert show];

这是我的错误:

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<ScheduleView: 0x8adf1a0> should have parent view controller:<_UIModalItemAccessoryViewControllerForLegacyAlert: 0xa888b70> but actual parent is:<UINavigationController: 0x8add8c0>'

我真的是 iOS 开发的新手。我做错了吗?错误在哪里?我不知道这里所说的 Nib 文件是什么“loadNibNamed:@bla boa”,我只是为此提供了我的 xib 名称。谁能给我一个更好的方法来做到这一点,或者你能告诉我我必须改变哪里才能解决这个问题吗?

请指导我一些.. 谢谢。

最佳答案

关于ios - 将自定义 View 添加到警报 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23285750/

相关文章:

ios - 如何使容器 View 内的 TableView 不会在键盘弹出窗口上弹起?

ios - UIScrollView 设置 contentInset.top 不将内容 View 向下推?

ios - UIAlertView 运行模式

objective-c - 应用程序在 [UIAlertView show] 上崩溃

iOS:自动布局与 autoresizingMask - 调整整个 View 的大小以填充?

ios - 将 UITextField 连接到 SLComposeViewController - swift

ios - 根据 iDevice 磁强计读数旋转 UIView

ios - 使用 UIAlertViewStylePlainTextInput 编辑注释文本

iOS @IBOutlet views all be nil only in iOS 8

ios - 我可以将自定义 xib 连接到框架中的类吗?