iDec
iDec

Reputation: 727

UITableViewCell as Button

I'm using an UITableViewCell to show UIActivityViewController but the problem is that once I've clicked the cell the UIActivityViewController doesn't appear until I click other cell 3 times or until I click a cell that shows another ViewController, here is when it appears but in the new ViewController and I want it in the same ViewController where the cell is.

The cell that I want to show UIActivityViewController is in a TableViewController.

Here is the code I'm using:

- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([indexPath isEqual:[tableView indexPathForCell:self.shareCell]]) {
    NSString *shareText = [NSString stringWithFormat:@"Text to share"];
    NSArray *shareObject = @[shareText];
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:shareObject applicationActivities:nil];
    [self presentViewController:activityViewController animated:YES completion:nil];
}

}

I have an IBOutlet for UITableViewCell in my .h file implemented in .m.

Thank you in advance!

Upvotes: 0

Views: 305

Answers (1)

Pancho
Pancho

Reputation: 4143

You are calling wrong method. This is getting called when cell is de-selected

- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

Use this instead:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Upvotes: 4

Related Questions