我一直试图解决与this question完全相同的问题一段时间,但我遇到了麻烦。我几个月才在XCode上工作,所以非常感谢帮助。
在我的父母VC.m中我有这个:
parentVC.m
- (IBAction)goToCamera:(id)sender {
[_camera takePhoto];
} return;
}
这在相当于James的PhotoManager类中调用takePhoto方法:一个名为Camera的NSObject类 - 我在其中设置了UIImagePickerController。我在标题中说明了方法:
Camera.h
- (void) takePhoto;
然后在实施中:
Camera.m
@class ParentVC;
@interface Camera () <UIImagePickerControllerDelgate, UINavigationControllerDelegate>
@property (nonatomic, retain) ParentVC *parentVC;
@end
@implementation Camera
-(void)takePhoto
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.delegate = self;
[_parentVC presentViewController:cameraUI animated:NO completion:nil];
}
else{
DLog(@"camera wouldn't load");
}
}
@end
没有运气。我尝试了很多迭代,但无法弄清楚。有什么想法吗?