问题
I'm new to iOS development so I'm confused. I have a ViewController, in this ViewController there are many UIButtons. How I can open the picker and add the image to the tweet using addImage
?
PS: I'm using Storyboard.
Thanks and sorry for my english... :)
回答1:
when the button is pressed, you want to do something like:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
}
you need to implement the delegate methods. the main one is:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *imageData = UIImagePNGRepresentation(image);
// do twitter stuff here....
[self dismissModalViewControllerAnimated:YES];
}
for more information, see the docs: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/PickinganItemfromthePhotoLibrary.html#//apple_ref/doc/uid/TP40010408-SW1
来源:https://stackoverflow.com/questions/8991613/how-i-can-use-a-uiimagepickercontroller-to-add-an-image-to-a-tweet