问题描述
我想在不同的情况下显示 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];