当单元格被触摸时,表格视图不会推向新视图

问题描述:

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

+0

你肯定在IB的SEGUE实际上是所谓的“showtext”? – ratbum 2012-07-21 23:16:57

prepareForSegue方法没有被调用。要调用它下面的方法一定要到位:

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