Monday, June 17, 2013

UIActionSheetDelegate actionSheet willDismissWithButtonIndex example in Objective C (iOS).

UIActionSheetDelegate actionSheet willDismissWithButtonIndex

Sent to the delegate before an action sheet is dismissed.

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex

Parameters of [UIActionSheetDelegate actionSheet willDismissWithButtonIndex]
The action sheet that is about to be dismissed.
The index of the button that was clicked. If this is the cancel button index, the action sheet is canceling. If -1, the cancel button index is not set.

Discussion of [UIActionSheetDelegate actionSheet willDismissWithButtonIndex]
This method is invoked before the animation begins and the view is hidden.

UIActionSheetDelegate actionSheet willDismissWithButtonIndex example.
NSString * videoLink;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
UIActionSheet *sheet = [[UIActionSheet alloc]

videoLink = \"URL to my movie\";
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)indexPath

Example of [UIActionSheetDelegate actionSheet willDismissWithButtonIndex].
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//Lanch movie player here with video url at indexPath
//NSString * yourMoviePath = @\"\";

// Navigation logic
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * description = [[stories objectAtIndex: storyIndex] objectForKey: @\"summary\"];

UIActionSheet *sheet = [[UIActionSheet alloc]
initWithTitle: NSLocalizedString(description, \"\")
cancelButtonTitle:NSLocalizedString(@\"Cancel\", \"\")
otherButtonTitles:NSLocalizedString(@\"Watch video\", \"\"), nil];
[sheet showInView:self.view];
[sheet release];

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)indexPath
    NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
    switch (indexPath)
        case 0:
NSString * videoLink = @\"\";
NSLog(@\"Playing video: %@\", videoLink);

NSURL *movieURL = [[NSURL URLWithString:videoLink] retain];

MPMoviePlayerController *DingPlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[DingPlayer play];
        } break;
    [self.tableView deselectRowAtIndexPath:selectedIndexPath animated:YES];

End of UIActionSheetDelegate actionSheet willDismissWithButtonIndex example article.