如何使用swift在两个不同数组的表格中填充两个部分?
发布时间:2020-12-14 05:53:41 所属栏目:百科 来源:网络整理
导读:我有两个数组Data1和Data2,我想将这些数据(它们包含字符串)中的数据填充到两个不同部分的表视图中。 第一部分应该有一个标题“Some Data 1”,第二部分应该标题为“KickAss”。 我有两个部分填充第一个数组的数据(但也没有标题)。 这是我的代码到目前为止 o
我有两个数组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方法中所做的那样?另外,如何给每个部分的标题?
您可以通过查看indexPath.section来确定您所在的部分。
要指定标题,请覆盖该功能 func tableView(tableView: UITableView!,titleForHeaderInSection section: Int) -> String! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |