2012-07-21 59 views
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不顯示任何警告或錯誤。這裏有什麼問題?

+0

你肯定在IB的SEGUE實際上是所謂的「showtext」? – ratbum 2012-07-21 23:16:57

回答

1

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

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