【问题标题】:How to change the UITableViewCell content view by IBAction?如何通过 IBAction 更改 UITableViewCell 内容视图?
【发布时间】:2012-05-01 17:21:18
【问题描述】:

我有一个包含许多单元格的 UITableView,所有单元格都进入一个 xib 视图,我在那个 xib 视图中有 2 个按钮 - 向上、向下。 我想要做的是在按下这些按钮之一时跳转到下一个/后退单元格内容,内容视图需要更改,如 Mail.app、Reeder 应用程序等......

这是我尝试做的,但没有成功:

  NSIndexPath *currentPath = [tipsGuideViewTv indexPathForSelectedRow];
  NSIndexPath *nextPath = [NSIndexPath indexPathForRow:indexVariable.row+1         inSection:indexVariable.section];

 [self.navigationController popToViewController:nextPath animated:YES];

我在网上搜索解决方案,但我没有找到我的意思。 有人知道怎么做吗?

谢谢。

【问题讨论】:

  • 我认为你的意思是使用 currentPath 而不是 indexVariable

标签: objective-c uitableview ibaction nsindexpath


【解决方案1】:
NSIndexPath *currentPath = [tipsGuideViewTv indexPathForSelectedRow];
NSIndexPath *nextPath    = [NSIndexPath indexPathForRow:currentPath.row+1 
                                              inSection:currentPath.section];

[tipsGuideViewTv selectRowAtIndexPath:nextPath animated:YES];

按 cmets 编辑

// To make it function the same as if they had tapped the row, do the following:
// Only call the methods that are implemented in your controller.
[tipsGuideViewTv tableView:tipsGuideViewTv willSelectRowAtIndexPath:nextPath];
[tipsGuideViewTv tableView:tipsGuideViewTv didSelectRowAtIndexPath:nextPath];

请确保新的索引路径有效(即您还不是表格的末尾)。

【讨论】:

  • 如果我从视图返回 UITableView,我会看到下一行被选中,但我想将视图更改为下一个单元格。与 Mail.app 一样,有两个箭头按钮可以将视图更改为下一个/后退单元格。我想通过 pushViewController 导航到该单元格
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多