对象在presentModalViewController之后返回null

时间:2011-08-08 17:01:42

标签: 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)

请帮忙!感谢。

2 个答案:

答案 0 :(得分:2)

  1. pickerOne必须是当前ViewController中的属性。
  2. 您当前的ViewController必须符合UIImagePickerControllerDelegate
  3. 的协议
  4. 在代理人的imagePickerController:didFinishPickingMediaWithInfo:实施中,您将获得图片对象并关闭modalViewController
  5. 这应该可以解决问题。

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

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

    注意: iOS 3.0

    中不推荐使用imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo

答案 1 :(得分:0)

我意识到在我驳回了这个观点后,我正在调用另一个类的动作。我只是把它作为NSNotification并且工作正常。

相关问题