Domanda

How can I still have my segues connected to my rows after I have edited the order of them (indexPath.row)? Now when I have changed the order of the rows, the segues goes to the wrong view, of course... Thanks in advance. Here's the relevant code.

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    NSString *stringToMove = self.objects[sourceIndexPath.row];
    [self.objects removeObjectAtIndex:sourceIndexPath.row];
    [self.objects insertObject:stringToMove atIndex:destinationIndexPath.row];   
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];    
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        cell.textLabel.text=self.objects[indexPath.row];
        return cell;
}

//segues
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Conditionally perform segues, here is an example:
    if (indexPath.row == 0)
    {
        [self performSegueWithIdentifier:@"segue 1" sender:self];
    }
    else if (indexPath.row ==1
    {
        [self performSegueWithIdentifier:@"segue 2" sender:self];
    }
    else if (indexPath.row ==2)
    {
        [self performSegueWithIdentifier:@"segue 3" sender:self];
    }
}
@end

("objects" is an NSarray with the stored rows.)

È stato utile?

Soluzione

solution:

    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *segueRow = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];     segueRow.textLabel.text=self.objects[indexPath.row]; 

if ([segueRow.textLabel.text isEqualToString:@"segue 1"]) 

{ [self performSegueWithIdentifier:@"white" sender:self]; 

} else if ([segueRow.textLabel.text isEqualToString:@"segue 2"]) 
{
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top