2013-04-05 151 views

回答

0

你有沒有提到照片庫意味着什麼?

下面一個是從照片庫

-(void)photoLibraryAction 
{ 
    NSLog(@"image"); 
    if(picker!=nil){ 
     [picker dismissModalViewControllerAnimated:YES]; 
     [test dismissPopoverAnimated:YES]; 
     picker.delegate=nil; 
     picker=nil; 
     test.delegate=nil; 
     test=nil; 
    } 
    picker= [[UIImagePickerController alloc] init]; 
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    picker.delegate=(id)self; 

    NSLog(@"%@",picker); 
    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) 
    { 
     [self presentModalViewController:picker animated:YES]; 
    } 
    // [self pre 
    else if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) 
    { 
     UIPopoverController *popImageLibrary=[[UIPopoverController alloc]initWithContentViewController:picker]; 
     test=popImageLibrary; 
     test.delegate=(id)self; 

     [test presentPopoverFromRect:CGRectMake(240, 730, 400, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; 
    } 

} 

訪問圖像並設置爲代表圖像選擇器

picker.delegate=(id)self; 

然後使用委託方法

- (void)imagePickerController:(UIImagePickerController *)albumPicker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone || albumPicker.sourceType==UIImagePickerControllerSourceTypeCamera) 
     { 
      self.imageData=[info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
       [albumPicker dismissModalViewControllerAnimated:YES]; 
     } 
     else 
     { 
      yourImageView.image=[info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
      [test dismissPopoverAnimated:YES];    

     } 

} 
代碼
相關問題