【问题标题】:Control two prototype cells of a single table view using segmented control of another view?使用另一个视图的分段控制来控制单个表视图的两个原型单元?
【发布时间】:2016-08-27 21:55:27
【问题描述】:

我有两个视图控制器,即“userTableViewController”和“InsertRecordViewController”。在 InsertRecordViewController 中,我有一个分段控件,用于控制 userTableViewController 的两个原型单元“cell1”和“cell2”。

有什么想法吗??

提前致谢!!

【问题讨论】:

  • 有什么问题?
  • 想不出办法将“userTableViewController”的原型单元格访问到我的“InsertRecordViewController”中
  • 你需要改变数据源
  • 我该怎么做??我是新手
  • 您需要根据您的要求在 cellForRowAtIndexPath 方法中设置条件准备单元格并返回它。

标签: ios uitableview swift2 uisegmentedcontrol


【解决方案1】:

首先你添加两个customTableViewCell。

然后导入你的 viewController 类。\

然后添加以下代码。它将对您有所帮助。

【讨论】:

  • 请勿截图,将代码以文字形式发布。
【解决方案2】:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    CustomTableViewCell *cell;

    AnotherTableViewCell *cell1;

    if(self.segmentedControl.selectedSegmentIndex == 0){

        cell =[[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

      }else{


         cell1 =[[AnotherTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

}

     if(self.segmentedControl.selectedSegmentIndex == 0){

        return cell;

    }else{

        return cell1;

  }

}

【讨论】:

    猜你喜欢
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多