Alloc类实例

时间:2013-05-14 13:19:55

标签: iphone ios objective-c uiimagepickercontroller

我有这堂课:

@class UIImagePicker;

@protocol UIImagePickerDelegate<NSObject>
@required

- (void)didFinishChooseImage:(UIImagePicker *)picker withImage:(UIImage*)img;

@end

@interface UIImagePicker : NSObject <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
    UIImagePickerController *imgPicker;
}

@property (assign) int type;
@property (nonatomic, retain) UIImagePickerController *imgPicker;
@property (nonatomic,assign) id <UIImagePickerDelegate> delegate;

这就是我如何分配imgPicker

-(void)showImagePicker{
    imgPicker = [[UIImagePickerController alloc] init];
    imgPicker.allowsEditing = YES;
    imgPicker.delegate = self;

    //Trigger get photo from library function
    if (self.type == 0) {
        imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    } else {
        imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
}

这就是我发布imgPicker

的方式
- (void)dealloc
{
    [imgPicker release],imgPicker = nil;
    [super dealloc];
}

dealloc中的发布是否正常?或者我需要添加另一个版本,因为imgPicker具有retain属性??

0 个答案:

没有答案