我是iOS开发的新手,所以我很困惑。我有一个ViewController,在这个ViewController中有很多UIButtons。如何打开选择器并使用addImage
将图像添加到推文中?
PS:我正在使用Storyboard。
谢谢,对不起我的英语......:)
答案 0 :(得分:5)
按下按钮时,您需要执行以下操作:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
}
您需要实现委托方法。主要是:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *imageData = UIImagePNGRepresentation(image);
// do twitter stuff here....
[self dismissModalViewControllerAnimated:YES];
}