【发布时间】:2013-12-31 11:22:31
【问题描述】:
在我编辑了它们的顺序 (indexPath.row) 之后,我怎样才能让我的 segues 连接到我的行?现在,当我更改了行的顺序时,segues 会转到错误的视图,当然...... 提前致谢。这是相关代码。
- (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" 是一个存储行的 NSarray。)
【问题讨论】:
-
没关系,我是这样解决的:
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"] ) {
标签: objective-c tableview segue didselectrowatindexpath