触摸单元格时,表视图不会推送到新视图

时间:2012-07-21 22:54:55

标签: objective-c ios5 uistoryboard uistoryboardsegue

我正在尝试从表视图导航到另一个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不会显示任何警告或错误。这有什么问题?

1 个答案:

答案 0 :(得分:1)

未调用prepareForSegue方法。要调用它,必须采用以下方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"showtext" sender:self];
}