显示相机后,我的对象返回 null:
下面是我如何显示我的 UIImagePickerController(我之前初始化它):
[self presentModalViewController:pickerOne animated:NO];
我像这样在我的 scrollView 中添加一个对象,
UIImageView *overlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"black_overlay.png"]];
[overlay setFrame:CGRectMake(((columnCount-1)*100)+((columnCount-1)*5)+5 ,((rowCount-1)*100)+((rowCount-1)*5)+11, 100, 100)];
[overlay.layer setCornerRadius:8.0];
[overlay.layer setMasksToBounds:YES];
[overlay setTag:12];
[theImageViewer addSubview:overlay];
然后像这样访问它(在相机关闭后):
UIImageView *overlayImage = (UIImageView*)[theImageViewer viewWithTag:[[arrayOverlays objectAtIndex:[arrayIds indexOfObject:imageThumbnail]] intValue]];
NSLog(@"OverlayImage: %@",[arrayOverlays objectAtIndex:[arrayIds indexOfObject:imageThumbnail]]);
我得到:Real overlayImage, (null)
求助!谢谢。
最佳答案
pickerOne
必须是当前 ViewController 中的一个属性。- 您当前的 ViewController 必须符合
UIImagePickerControllerDelegate
的协议(protocol)。 - 在委托(delegate)的
imagePickerController:didFinishPickingMediaWithInfo:
实现中,您将获得图像对象并关闭modalViewController
。
这应该可以解决问题。
编辑:刚刚找到了一个详细解释这个的教程:
http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/
注意:imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo
在 iOS 3.0
关于objective-c - 对象在 presentModalViewController 之后返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6985712/