答案 0 :(得分:1)
在UIVieController中添加xibView时,在ParentViewController中指定self。
即
_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];
}