我如何填充两个部分的实现代码如下使用SWIFT两个不同的阵列? [英] How do I populate two sections in a tableview with two different arrays using swift?
问题描述
我有两个数组数据1和Data2中,我想在每个这些填充数据(它们包含字符串)成两个不同的部分的实现代码如下。
第一部分应该具有一个标题一些数据1和第二部分应该标题为KickAss
I have two arrays Data1 and Data2 and I want to populate the data within each of these (they contain strings) into a tableview in two different sections. The first section should have a heading "Some Data 1" and the second section should be titled "KickAss".
我有两部分从第一阵列数据填充(但没有标题或)
I have both sections populating with data from the first array (but with no headings either).
下面是我的code迄今:
Here is my code so far:
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方法做?另外,我怎么给标题,以每节?
谢谢
in the cellForRowAtIndexPath method, is it possible for me to identify the section somehow like I did in the numberOfRowsInSection method? Also, how do I give titles to each section? Thanks
推荐答案
您可以决定你是通过看 indexPath.section
这部分。
要指定标题,覆盖功能
You can determine which section you are in by looking at indexPath.section
.
To specify the titles, override the function
func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String!
这篇关于我如何填充两个部分的实现代码如下使用SWIFT两个不同的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!