2014-10-27 60 views
-1

我有一个包含五个单元格的UITableView。每个单元格都有一个标签和一个图像。现在使用didSelectRowAtIndexPath,当我点击任何单元格时,会出现一个新视图,其中包含单击单元格中的标签和图像。代码是:UITableView didSelectRowAtIndexPath

OpenMessageViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"OpenMessageVC"]; 
    [self.navigationController pushViewController:controller animated:YES]; 

OpenMessageViewController是我的新视图,它会在单击单元格时出现。 我在故事板中的OpenMessageViewController中添加了一个标签和图像。如何将OpenMessageViewController的标签文本和图像更改为单击单元格中存在的文本和图像。 谢谢

+0

您的实际问题是什么?你的代码没有问题,除非你的Storyboard实际上并不包含可见的UINavigationController。 – 2014-10-27 10:47:59

+0

我已更新我的问题 – 2014-10-27 10:53:30

+0

查看http://stackoverflow.com/questions/7864371/ios-how-to-pass-prepareforsegue-an-object – 2014-10-27 10:55:36

回答

0

我没有把你的代码放在一个Xcode项目中,但是你不可以这样做来传递图像和文本吗?

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// Get the tapped cell 
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

// Configure the destination VC 
UIImageView *myImageView = (UIImageView *)[cell viewWithTag:10]; // Set tag 10 to the UIImageView in your cell 
UILabel *myLabel = (UILabel *)[cell viewWithTag:20]; // Set tag 20 to the UILabel in your cell 
controller.imageView.image = myImageView.image; 
controller.theLabel.text = myLabel.text; 

// Navigate 
[self performSegueWithIdentifier:@"mySegue" sender:self]; 
} 

记得在IB中连接两个ViewController。然后,您必须在目标ViewController上有一个名为theLabel的标签和一个名为imageView的imageView,它们连接到插座。 (随意更改名称)

+0

您可能需要进行一些调整以适合您的“控制器”参考。让我知道如果你有任何问题 – Erik 2014-10-27 12:24:58

+0

它的工作.. :)谢谢你 – 2014-10-27 12:49:17

+0

@mahivamsi很高兴帮助!;) – Erik 2014-10-27 12:58:57

相关问题