我有三节的桌面视图。我使用两个自定义单元格(一个用于第一个和最后一个部分,一个用于中间部分)。问题是,当初始加载后重新加载tableview时,即使第0节中的行数没有设置为1,它也会进入零部分两次。这是代码:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
var noOfRows = 0
switch(section){
case 0:
// if arraySearchResultODXTop.count > 0{
noOfRows = 1
// }
case 1:
if(array_SearchResults.count > 0){
noOfRows = array_SearchResults.count
}
case 2:
noOfRows = 1
default:
return 0
}
return noOfRows
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cellIdentifier:String?
switch (indexPath.section){
case 0, 2:
cellIdentifier = "cell1"
case 1:
cellIdentifier = "cell"
default:
cellIdentifier = "cell"
}
var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier!,forIndexPath: indexPath) as? UITableViewCell
var apartment:AFApartmentListing?
switch (indexPath.section){
case 0:
if (indexPath.row == 0){
println("section and row...\(indexPath.section),\(indexPath.row)")
if self.arraySearchResultODXTop.count > 0{
apartment = self.arraySearchResultODXTop[1] as? AFApartmentListing
}
var topCell:AFODXView? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier!, forIndexPath: indexPath) as? AFODXView
if (topCell == nil){
topCell = AFODXView(style: UITableViewCellStyle.Default, reuseIdentifier: cellIdentifier)
}
topCell!.setupCell(apartment)
cell = topCell! as AFODXView
break
}
case 1:
var cell:AFSearchResultsTableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier!, forIndexPath: indexPath) as? AFSearchResultsTableViewCell
if (cell == nil){
cell = AFSearchResultsTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: cellIdentifier)
}
apartment = array_SearchResults[indexPath.row] as? AFApartmentListing
cell!.delegate = self
cell!.setupCellWithApartment(apartment!)
cell = cell! as AFSearchResultsTableViewCell
break
case 2:
if (indexPath.row == 0){
println("last section...\(indexPath.section),\(indexPath.row)")
if self.arraySearchResultODXBottom.count > 0{
apartment = self.arraySearchResultODXBottom[0] as? AFApartmentListing
}
var bottomCell:AFODXView?
bottomCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier!, forIndexPath: indexPath) as? AFODXView
if (bottomCell == nil){
bottomCell = AFODXView(style: UITableViewCellStyle.Default, reuseIdentifier: cellIdentifier)
}
bottomCell!.setupCell(apartment)
cell = bottomCell! as AFODXView
break
}
default:
cell = nil
return cell!
}
return cell!
}