2011-04-07 68 views
1

嘿傢伙, 我知道它已經被更頻繁地詢問,但他們的問題的答案似乎並不適用於此。問題UIImagePickerControllerDelegate,didFinishPickingMediaWithInfo沒有調用

我didFinishPickingMediaWithInfo方法不會被調用:(

這裏是我的代碼:

的.H文件:

#import <UIKit/UIKit.h> 


@interface DevicePictureController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> { 

    UIImageView *photo; 
    UIButton *selectPhoto; 
    UIButton *takePhoto; 
    NSMutableDictionary *listLocations; 
    NSMutableDictionary *listDevices; 
    UIImagePickerController *picker; 
} 

@property (nonatomic, retain) IBOutlet UIImageView *photo; 
@property (nonatomic, retain) IBOutlet UIButton *selectPhoto; 
@property (nonatomic, retain) IBOutlet UIButton *takePhoto; 
@property (nonatomic, retain) UIImagePickerController *picker; 

-(IBAction)selectPicture:(id)sender; 
@end 

的的.m文件:#進口 「 DevicePictureController.h「

@implementation DevicePictureController 
@synthesize photo, selectPhoto, takePhoto, picker; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    listLocations = [[NSMutableDictionary alloc] init]; 
    listDevices = [[NSMutableDictionary alloc] init]; 
    picker = [[UIImagePickerController alloc] init]; 
} 

-(IBAction)selectPicture:(id)sender { 

    picker.delegate = self; 
    picker.allowsEditing = YES; 

    if ((UIButton *)sender == selectPhoto) { 

     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    } 
    else { 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    } 

    [self presentModalViewController:picker animated:YES]; 
} 

-(void)imagePickController:(UIImagePickerController *)picked didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    [picked dismissModalViewControllerAnimated:YES]; 
    NSLog(@"Geselecteerd: %@", [info objectForKey:UIImagePickerControllerEditedImage]); 
    //photo = [[UIImageView alloc] init]; 
    [photo setImage:[info objectForKey:UIImagePickerControllerEditedImage]]; 
} 

@end 

所以,我的相冊或我的相機被正確加載/激活,但是當我點擊「使用」或照片時,在視圖關閉後,我只能看到2個按鈕和一個模糊的UIImageView。 'photo'連接到UIImageView,'selectPhoto'和'takePhoto'連接到它們的按鈕,'selectPicture'連接到兩個按鈕'Touch Up Inside-action'。 有人可以幫我嗎?

回答

5

您在刪除方法中有錯字。

應該

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 

,但你必須

- (void)imagePickController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
+0

,我不知道我是否應該自己買一些新的眼鏡,或只是一頭扎進牀上。謝謝隊友(10分鐘後可以接受答案,不知何故) – Joetjah 2011-04-07 12:23:11

+0

沒問題。我去過那兒! – CharlieMezak 2011-04-07 12:25:23

+0

你打了我約50秒。所以避免重複的答案和投票你的答案 – visakh7 2011-04-07 12:27:16

1
- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
listLocations = [[NSMutableDictionary alloc] init]; 
listDevices = [[NSMutableDictionary alloc] init]; 
picker = [[UIImagePickerController alloc] init]; 
picker.delegate = self; 
} 
+0

只是用這個替換你的viewDidLoad。設置picker.delegate = self; 所以它會調用它的委託方法didFinishPickingMediaWithInfo調用 – 2011-04-07 12:22:42

相關問題