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