我有两个数组Data1和Data2,我想将每个数组中的数据(它们包含字符串)填充到两个不同部分的表视图中。第一部分的标题为“ Some Data 1”,第二部分的标题为“ KickAss”。
我都有两个部分都填充了第一个数组中的数据(但也没有标题)。>>
到目前为止是我的代码:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 2 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { var rowCount = 0 if section == 0 { rowCount = Data1.count } if section == 1 { rowCount = Data2.count } return rowCount } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell let ip = indexPath cell.textLabel?.text = Data1[ip.row] as String return cell }
在cellForRowAtIndexPath方法中,像我在numberOfRowsInSection方法中所做的一样,是否可以标识该节?另外,如何给每个部分标题?谢谢
我有两个数组Data1和Data2,我想将每个数组中的数据(它们包含字符串)填充到两个不同部分的表视图中。第一部分应具有标题“ Some ...
TableView单元格
您可以创建一个Struct
来保存属于某个部分的数据,以替代我以前的回答。例如:
您可以通过查看indexPath.section
来确定您所在的部分。要指定标题,请覆盖功能
在swit 4或swift 5中,您可以使用like。这里显示了自定义标头部分wit过滤器