-2

我有一个UIImage属性,从 iPhone 相机拍摄图像后,我将图像对象分配给该属性,否则没有。拍摄后如何检查此属性是否包含图像?下面我的代码没有帮助。

@interface MyViewController : UIView<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property(nonatomic, retain) UIImage *imageShot;
@end

@implementation MyViewController
@synthesize imageShot = _imageShot;

- (id)init {
    self = [super init];
    if (self) {
        _imageShot = [[UiImage alloc] init];
    }
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    self.imageShot = [info objectForKey:UIImagePickerControllerEditedImage];
}

- (void)buttonClick {
    if (_imageShot) {

    } 
    else {

    }
}

@end
4

1 回答 1

6

在您的init中,您应该创建shotedImagenil不是分配一个新的空图像。这将允许执行像if (!shotedImage)(as nil == 0) 这样的测试。

于 2012-06-11T07:45:09.630 回答