1

我正在尝试从表格视图导航到另一个 UIViewController。我在新的 UIViewController 中控制拖动我的 TableCell。然后我输入了以下代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    // Configure the cell...
    if (cell == nil) {
        cell = [[ UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    if ([indexPath section] == 0) {
        Tips *tipy = [arr objectAtIndex:indexPath.row];
        cell.textLabel.text = [tipy tipdescription];
        cell.detailTextLabel.text = [tipy.tipnumber stringValue];
        NSString *imagefile = [[ NSBundle mainBundle] pathForResource:@"unlikeico" ofType:@"png"];
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagefile];
        [[cell imageView]setImage:image];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            } else {
                Tips *tipy = [arr2 objectAtIndex:indexPath.row];
                cell.textLabel.text = [tipy tipdescription];
                cell.detailTextLabel.text = [tipy.tipnumber stringValue];
                NSString *imagefile = [[ NSBundle mainBundle] pathForResource:@"likeico" ofType:@"png"];
                UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagefile];
                [[cell imageView]setImage:image];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                    }

    return cell;
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"showtext"]) {

        DisplayViewController *dvc = [segue destinationViewController];
        NSIndexPath *path = [self.tableView indexPathForSelectedRow];
        Tips *tipy = [arr2 objectAtIndex:[path row]];  
        [dvc setCurrenttext:tipy];
    }

}

该表将显示数据,但不会移动到新的 UIViewController。Xcode 不显示任何警告或错误。这里有什么问题?

4

1 回答 1

1

prepareForSegue方法没有被调用。要调用它,必须有以下方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"showtext" sender:self];
}
于 2012-07-22T17:10:08.773 回答