Wednesday, June 12, 2013

UIActionSheet actionSheet willDismissWithButtonIndex example in Objective C (iOS).

UIActionSheet actionSheet willDismissWithButtonIndex

Sent to the delegate before an action sheet is dismissed.

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

Parameters of [UIActionSheet actionSheet willDismissWithButtonIndex]
actionSheet
The action sheet that is about to be dismissed.
buttonIndex
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 [UIActionSheet actionSheet willDismissWithButtonIndex]
This method is invoked before the animation begins and the view is hidden.

UIActionSheet 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
{
    NSLog(videoLink);
}

Example of [UIActionSheet actionSheet willDismissWithButtonIndex].
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Lanch movie player here with video url at indexPath
//NSString * yourMoviePath = @\"http://vpodcast.dr.dk/DR2/Soeinding/2009/Soeinding_0910272030.mp4\";


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

UIActionSheet *sheet = [[UIActionSheet alloc]
initWithTitle: NSLocalizedString(description, \"\")
delegate:self
cancelButtonTitle:NSLocalizedString(@\"Cancel\", \"\")
destructiveButtonTitle:nil
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 = @\"http://vpodcast.dr.dk/DR2/Soeinding/2009/Soeinding_0910132030.mp4\";
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 UIActionSheet actionSheet willDismissWithButtonIndex example article.