2013-04-05 152 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];    

     } 

} 
代码
相关问题