Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用自定义单元格创建多个分区_Ios_Swift_Uitableview - Fatal编程技术网

Ios 使用自定义单元格创建多个分区

Ios 使用自定义单元格创建多个分区,ios,swift,uitableview,Ios,Swift,Uitableview,所以我在一个表视图中有两个自定义单元格。每个单元格都有自己的单独部分,“筛选”和“排序方式” 我试图用这些标题显示每个部分,但问题是两个部分显示相同的自定义单元格。我的假设是,我需要每个部分通过标识符来检测要显示的自定义单元格,但我似乎无法理解这一点。我也不确定我是否应该使用switch语句,但看起来似乎是合理的 func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UIT

所以我在一个表视图中有两个自定义单元格。每个单元格都有自己的单独部分,“筛选”和“排序方式”

我试图用这些标题显示每个部分,但问题是两个部分显示相同的自定义单元格。我的假设是,我需要每个部分通过标识符来检测要显示的自定义单元格,但我似乎无法理解这一点。我也不确定我是否应该使用switch语句,但看起来似乎是合理的

func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell {
    if indexPath.section == 0 {
        let cell = tableView.dequeueReusableCellWithIdentifier("SortByCell") as! SortByCell
        // Edit cell here
        return cell
    }
    let cell = tableView.dequeueReusableCellWithIdentifier("FilterCell") as! FilterCell
        // Edit cell here
    return cell
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 2
}

func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int {
    return 1
}

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    switch section {
    case 0:
        return "Sort By"
    default:
        return "Filter"
    }
}

在我的帖子中添加了CellForRowatineXpath部分。尽管如此,两个部分都显示了SortByCellOH,但我完全错过了实际需要做的事情,只是indexPath.section而不是indexPath.row。我现在觉得自己很愚蠢。
func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell {
    if indexPath.section == 0 {
        let cell = tableView.dequeueReusableCellWithIdentifier("SortByCell") as! SortByCell
        // Edit cell here
        return cell
    }
    let cell = tableView.dequeueReusableCellWithIdentifier("FilterCell") as! FilterCell
        // Edit cell here
    return cell
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 2
}

func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int {
    return 1
}

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    switch section {
    case 0:
        return "Sort By"
    default:
        return "Filter"
    }
}