我有一个通过UIStoryboardPopoverSegue调用的viewcontroller,里面有一个调用imagePickerController的按钮,它可以用于第一次调用但第二次崩溃。
如果没有通过UIStoryboardPopoverSegue,代码就可以使用了。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum (image, nil, nil , nil);
[self dismissViewControllerAnimated:YES completion:nil];
}
-(IBAction)takephoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.delegate=self;
self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (!self.imagePicker)
{
self.imagePicker = [[UIImagePickerController alloc] init];
}
}
我启用了NSZobmbie来显示任何可以帮助我跟踪它的日志。
* - [UIImagePickerController isKindOfClass:]:发送给的消息 解除分配的实例0x1eb3b700
答案 0 :(得分:1)
您的UIImagePickerController已发布,之后尝试访问 - 因此崩溃了!
要修复它,请使UIImagePickerController成为拥有实例的强引用属性:
@property (strong, nonatomic) UIImagePickerController *imagePicker;
初始化一次:
if (!self.imagePicker) self.imagePicker = [[UIImagePickerController alloc] init];
并使用:
[self.imagePicker doStuff]
进行访问。
那应该解决它。
修改强>
if ([[segue identifier]isEqualToString:@"tcwindshield"]) {
self.ips = [segue destinationViewController];
self.ips.delegate = self
self.ips.strStatValue=@"WindShield";
}