user2650439
user2650439

Reputation: 207

Combine didSelectRowAtIndexPath and prepareForSegue

I have the following problem: The segue should only be performed if the UITableViewCellSelectionStyleNone is true.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell.selectionStyle == UITableViewCellSelectionStyleNone) {
        [self performSegueWithIdentifier:@"Update" sender:indexPath];{

        }
    }
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{          
    if ([[segue identifier] isEqualToString:@"Update"]) {
        NSManagedObject *selected = [self.travelA objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
        TravelVC *destViewController = segue.destinationViewController;
        destViewController.travel = selected;
        destViewController.positionString =  _positionStringA;
    }
}

But this doesn't work. The segue will also be performed if the cell selection style is not UITableViewCellSelectionStyleNone. Maybe there's a way to combine both methods.

Thanks in advance.

Upvotes: 1

Views: 525

Answers (1)

Wain
Wain

Reputation: 119031

You shouldn't be basing your logic on the cell setting of UITableViewCellSelectionStyleNone. Instead, you should be using the indexPath to interrogate your model and find out if selection is available / sensible for that item.

Upvotes: 1

Related Questions