UIAlertController 不工作 Xibs?
UIAlertController not working Xibs?
在我的项目中,我正在使用 xib,因为我想显示 UIAlertController 并执行一些 actions.but 我收到错误。
这是我的代码。
我的代码有什么错误。
当在 UIVieController 中添加 xibView 时,在 ParentViewController 中分配自己。
即
_xibView *objxibView = [[xibView alloc]init];
objxibView.parentViewController = self;
在 Xib 的 xibView.h 文件中创建 1 属性
@property (weak, nonatomic) UIViewController *parentViewController;
并在 xibView.m 文件中使用以下代码
对于 xib 中的 UIAlertController
{
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionOK = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:actionOK];
[self.parentViewController presentViewController:alert
animated:YES
completion:nil];
}
在我的项目中,我正在使用 xib,因为我想显示 UIAlertController 并执行一些 actions.but 我收到错误。
这是我的代码。
我的代码有什么错误。
当在 UIVieController 中添加 xibView 时,在 ParentViewController 中分配自己。
即
_xibView *objxibView = [[xibView alloc]init];
objxibView.parentViewController = self;
在 Xib 的 xibView.h 文件中创建 1 属性
@property (weak, nonatomic) UIViewController *parentViewController;
并在 xibView.m 文件中使用以下代码 对于 xib 中的 UIAlertController
{
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionOK = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:actionOK];
[self.parentViewController presentViewController:alert
animated:YES
completion:nil];
}