如何解决在为 init 调用 func 后,UIAlertController 保持为 nil
我想在不同的情况下显示 2 个警报,我编写了一个通用函数来 init
开始时的警报并稍后更改消息,但是当我尝试显示警报时,我遇到了崩溃.当我在运行时检查 notesAlert
时它仍然为零。
谁能解释一下我做错了什么?
@interface viewController (){
UIAlertController *tableAlert;
UIAlertController *notesAlert;
}
@end
@implementation viewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initAlert:tableAlert];
[self initAlert:notesAlert];
}
// func to init the alerts
-(void)initAlert:(UIAlertController*)alert{
alert = [UIAlertController alertControllerWithTitle: @"" message: @"" preferredStyle:UIAlertControllerStyleActionSheet];
[alert setModalPresentationStyle:UIModalPresentationPopover];
[alert.popoverPresentationController setSourceView:self.view];
UIPopoverPresentationController *popover = [alert popoverPresentationController];
CGRect popoverFrame = CGRectMake(0,self.view.frame.size.width/2,self.view.frame.size.width/2);
popover.sourceRect = popoverFrame;
UIAlertAction *dismiss = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:dismiss];
}
- (IBAction)showNotes:(id)sender {
// here the notesAlert is still nil
[notesAlert setTitle:@"oops"];
[notesAlert setMessage:@"you pressed the wrong one"];
[self presentViewController:notesAlert animated:YES completion:nil];
}
@end
解决方法
In [67]: z = truncnorm.rvs(a,b,loc,scale,size=100000)
In [68]: plt.hist(z,bins=100)
不会创建 [self initAlert: notesAlert];
。相反,您可以使用 notesAlert
也许是这样的:
notesAlert = [self initAlert];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。