Database Reference
In-Depth Information
Adding an Action Sheet for our photoTapped: Method
Next we need to add our photoTapped: method so that something actually happens when we tap the
image.
-(void)photoTapped:(UIGestureRecognizer *)gesture {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Change Photo" delegate:self
cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo",@"Choose From
Library",nil];
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
In this method we create a simple action sheet to ask the user if they want to take a photo with their
camera or choose a photo from the photo library. We call the method showFromTabBar: because this
view resides inside a UITabBarController .
Now we need to add a delegate method for the UIActionSheet called actionSheet:
clickedButtonAtIndex: .
#pragma mark - UIActionSheetDelegate Methods
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(_picker != nil){
[_picker dismissViewControllerAnimated:NO completion:nil];
_picker = nil;
}
switch (buttonIndex) {
case 0: {
_picker = [[UIImagePickerController alloc] init];
[_picker setDelegate:self];
[_picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[_picker setAllowsEditing:YES];
[self presentViewController:_picker animated:YES completion:nil];
} break;
case 1: {
_picker = [[UIImagePickerController alloc] init];
[_picker setDelegate:self];
[_picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[_picker setAllowsEditing:YES];
[self presentViewController:_picker animated:YES completion:nil];
} break;
default:
break;
}
}
 
Search WWH ::




Custom Search