【发布时间】:2015-06-17 04:58:49
【问题描述】:
我有两个数组 Data1 和 Data2,我想将每个数组中的数据(它们包含字符串)填充到两个不同部分的 tableview 中。
第一部分的标题应为“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 方法中那样识别部分?
另外,如何为每个部分指定标题?
【问题讨论】:
-
我已经搜索了几个小时,这是唯一对我有用的东西。非常感谢。
标签: arrays uitableview swift sections