swift - 带有 TableView 的 Swift 4 SegmenterControl
问题描述
我建立了一个社交应用程序,现在我想做出一些漂亮的外表。我想从 segmentedCntrol 更改标签联系人/房间。我怎样才能用正确的形式做到这一点?我有两种方法...清除联系人表视图并用房间数据填充它。或者使用表格视图隐藏视图并使用新的 tableView 显示另一个视图。
解决方案
cellForRowAt
您应该创建 2 个 tableViewCells 并根据选定的段在它们之间切换
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
}
}
推荐阅读
- sql - 如何使用 redshift 从表中解析 JSON
- javascript - 三点语法不复制数组
- c# - 如何确定office 2016、2019和365
- sql-server - 使用带有 SQL 游标的 case 语句对每一行执行计算并对结果求和
- python - python AttributeError - 模块 'os' 没有属性 'mkfifo' // 替代 Windows
- apache-drill - 使用 group by 查询以获取列中的逗号分隔值
- java - Apache Camel Route 中未显示新行字符
- python - Python solve_ivp 事件函数
- sql - R 行号 df
- amazon-web-services - 无法将数据从 fluentd 发送到 Amazon Hosted Kafka