UIImagePickerController问题

时间:2009-07-29 13:54:38

标签: objective-c

在我的应用中,我有两个视图控制器。按下按钮时,MainViewController切换到AlbumViewController。 AlbumVC应该允许用户从PhotoLibrary和/或CameraRoll中选择一张图片。所以,我尝试启动UIImagePickerController。

然而,当应用程序运行时,我根本看不到UIImagePickerController。不是编译器错误,也没有运行时错误。

善良的灵魂可以帮助我!

这是源.....山姆

MainViewController.h

    #import <UIKit/UIKit.h>

    @interface iNotateViewController : UIViewController {

    }

@end

MainViewController.m

#import "iNotateViewController.h"

@implementation iNotateViewController

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [super dealloc];
}

@end

AlbumViewController.h

#import <UIKit/UIKit.h>
#import <UIKit/UIViewController.h>

@interface AlbumViewController : UIViewController <UINavigationControllerDelegate,
                                                    UIImagePickerControllerDelegate >{

}
@end

AlbumViewController.m

    - (void)viewDidLoad {

        [super viewDidLoad];

        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
            UIImagePickerController *picker;
            picker = [[UIImagePickerController alloc] init];
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.allowsImageEditing = YES;

            picker.delegate = self;

            [self presentModalViewController:picker animated:YES];

            [picker release];       
        }
    }


    -(void)imagePickerController: (UIImagePickerController *) picker
           didFinishPickingImage: (UIImage *) image
                     editingInfo: (NSDictionary *) editingInfo {
        [self useImage:image];
        [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    }

    -(void)imagePickerControllerDidCancel: (UIImagePickerController *)picker {
        [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    }
@end

2 个答案:

答案 0 :(得分:0)

我相信你应该将[picker release]移动到dealloc方法

答案 1 :(得分:0)

AlbumViewController.m 中,更改方法- (void)viewDidLoad中的以下代码行

自:

[self presentModalViewController:picker animated:YES];

要:

[self.navigationController presentModalViewController:picker animated:YES];