我有这样的问题:
我想在警报 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 名称。谁能给我一个更好的方法来做到这一点,或者你能告诉我我必须改变哪里才能解决这个问题吗?
请指导我一些.. 谢谢。
最佳答案
此 API 可以解决您的问题,使用它并享受乐趣
https://github.com/Darktt/DTAlertView
https://github.com/Scott90/SDCAlertView
关于ios - 将自定义 View 添加到警报 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23285750/