如何使用swift在两个不同数组的表格中填充两个部分?

前端之家收集整理的这篇文章主要介绍了如何使用swift在两个不同数组的表格中填充两个部分?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个数组Data1和Data2,我想将这些数据(它们包含字符串)中的数据填充到两个不同部分的表视图中。
第一部分应该有一个标题“Some Data 1”,第二部分应该标题为“KickAss”。 @H_404_2@我有两个部分填充第一个数组的数据(但也没有标题)。

@H_404_2@这是我的代码到目前为止

  1. override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
  2. return 2
  3. }
  4.  
  5. override func tableView(tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
  6. var rowCount = 0
  7. if section == 0 {
  8. rowCount = Data1.count
  9. }
  10. if section == 1 {
  11. rowCount = Data2.count
  12. }
  13. return rowCount
  14. }
  15. override func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  16. let cell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath) as UITableViewCell
  17. let ip = indexPath
  18. cell.textLabel?.text = Data1[ip.row] as String
  19. return cell
  20. }
@H_404_2@在cellForRowAtIndexPath方法中,是否可以识别这个部分,就像我在numberOfRowsInSection方法中所做的那样?另外,如何给每个部分的标题
谢谢

您可以通过查看indexPath.section来确定您所在的部分。
要指定标题,请覆盖该功能
  1. func tableView(tableView: UITableView!,titleForHeaderInSection section: Int) -> String!

猜你在找的Swift相关文章