如何在对我的数组的indexPath调用中指定section和row?

时间:2015-02-12 03:37:03

标签: ios uitableview nsindexpath

以前,我使用以下代码填充我的TableView:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cellIdentifier = "Cell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath:
        indexPath) as CustomTableViewCell

    let entry = entries[indexPath.row]
    cell.entryLabel!.text = entry.labelOne
    cell.entryDayLabel!.text = entry.day
    cell.entryDateLabel!.text = entry.date

    return cell
}

我已经在我的表中添加了部分,并且我无法确定如何在此数组调用中指定部分和行。

我试过

let entry = entries[indexPath.section]

我试过

let entry = entries[indexPath.row + indexPath.section]

但两种方法都不正常。

有没有正确的方法来做到这一点,我错过了?任何帮助是极大的赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

indexPath.section 

将返回当前部分。

您通常想要做的是添加一些条件逻辑,如:

if(indexPath.section == 0)
{
    entry = entries[indexPath.row]
}
else if(indexPath.section == 1)
{
    entry = whateverDataSource[indexPath.row]
}

您是否为部分使用了两种不同的表格和/或单元格类型?