【问题标题】:Swift 4 SegmenterControl with TableView带有 TableView 的 Swift 4 SegmenterControl
【发布时间】:2018-05-10 15:57:22
【问题描述】:

我创建了一个社交应用程序,现在我想做一些漂亮的外观。我想从 segmentedCntrol 更改标签联系人/房间。我怎样才能用正确的形式做到这一点?我有两种方法...清除联系人表视图并用房间数据填充它。或者使用 tableView 隐藏视图并使用新 tableView 显示另一个视图。

【问题讨论】:

  • 您可以使用一个带有两个原型单元格的表格视图。
  • @RajeshKumarR 只是在索引更改时清理 tableView?
  • 是的。在 cellForRow 方法中检查段控制索引并使用适当的原型单元
  • @RajeshKumarR 好的,谢谢!)

标签: swift tableview customization uisegmentedcontrol


【解决方案1】:

您应该创建2个tableViewCells并根据所选段在cellForRowAt之间切换

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if  mySegment.selectedSegmentIndex == 0
    {
        let cell = tableView.dequeueReusableCell(withIdentifier:CellIdentifier1) as!  Cell1

       // setup here

   }
   else{

        let cell = tableView.dequeueReusableCell(withIdentifier:CellIdentifier2) as!  Cell2

        // setup here
   }
}

【讨论】:

    猜你喜欢
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2015-05-04
    相关资源
    最近更新 更多