【问题标题】:How reuse UITableViewCell view which is created in Storyboard in different UItableViewController?如何在不同的 UItableViewController 中重用 Storyboard 中创建的 UITableViewCell 视图?
【发布时间】:2013-08-22 12:37:31
【问题描述】:

您好,我在 Storyboard 的 ControllerA 中创建了 UITableViewCell。我需要在不同的 ControllerB 中使用相同的 UITableViewcell。我只需要使用情节提要来实现这一点。 知道我该怎么做吗?

【问题讨论】:

  • 这里已经有解决方案了:stackoverflow.com/questions/9245969/…
  • 您需要创建一个 .xib 文件(在 XCode 6 中,您可以在创建新的 xib 文件后复制 tableview 单元格的粘贴内容)

标签: ios objective-c mobile uitableview storyboard


【解决方案1】:

你可以像下面这样使用它:-

在故事板中,您必须将另一个 Table-cell 放入 ControllerB nib 并为其指定您想要类似于下面的自定义单元格的类名:-

和

你的 ControllerB 的 cellForRowAtIndexPath 看起来像这样

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    Members_Cell *cell  = [tableView dequeueReusableCellWithIdentifier:@"Members_Cell"];

    cell.lblMemberName.text=[ArrSearchResult objectAtIndex:indexPath.row];

    return  cell;

}

【讨论】:

  • 正确检查这是我在项目中使用的工作方法,我认为您忘记在 secondviewcontroller xib 的故事板上设置 tableview 单元格的客户类
  • 我需要在 ControllerA 和 ControllerB 中设置具有相同标识符的自定义类吗?
猜你喜欢
  • 2016-03-15
  • 1970-01-01
  • 2012-03-10
  • 2011-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-12
  • 2013-09-03
相关资源
最近更新 更多