objective-c - 对象在 presentModalViewController 之后返回 null

标签 objective-c ios null

显示相机后,我的对象返回 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)

求助!谢谢。

最佳答案

  1. pickerOne 必须是当前 ViewController 中的一个属性。
  2. 您当前的 ViewController 必须符合 UIImagePickerControllerDelegate 的协议(protocol)。
  3. 在委托(delegate)的 imagePickerController:didFinishPickingMediaWithInfo: 实现中,您将获得图像对象并关闭 modalViewController

这应该可以解决问题。

编辑:刚刚找到了一个详细解释这个的教程:

http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/

注意:imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfoiOS 3.0

中已弃用

关于objective-c - 对象在 presentModalViewController 之后返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6985712/

相关文章:

ios - UILocalNotification - 打开应用程序后继续播放提示音

ios - 如果我的 Mac 没有连接 iOS 设备, "Build active architecture only"会做什么吗?

java - Orika 没有映射列表中的空元素

c# - 处理链式 linq-to-sql 查询表达式中的空值

python - 如何使用 PyObjC 在 WebKit WebView 中加载用户 CSS?

ios - 作为自己的委托(delegate)的类是否遵循 iOS 约定?

iphone - 单击自定义按钮时如何通过@selector 传递数据?

ios - 如何进入聊天室+ xmpp?

iphone - URL 图片问题 iphone

c++ - 在删除/释放优化函数调用之前不会进行空检查吗?