这是cellforrow的方法,当我尝试使用restkit获取类别和子类别,类别获取suceesfully但每当我尝试获取子类别时我发现致命错误:索引超出范围 .
func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) - > UITableViewCell {
let section = getSectionIndex(indexPath.row)
let row = getRowIndex(indexPath.row)
if row == 0
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1") as! Menu1
cell.lbl.text = data[section].name!
cell.btn.tag = section
cell.btn.setImage(sections[section].collapsed! ? #imageLiteral(resourceName: "right"):#imageLiteral(resourceName: "Down"), for: UIControlState())
cell.btn.addTarget(self, action: #selector(MenuViewController.toggleCollapse), for: .touchUpInside)
return cell
}
else
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell2") as! MenuTableViewCell!
cell?.lbl.text = sections[section].items[row - 1]
cell?.myimg.image = sections[section].img1[row - 1]
cell?.lbl.textColor = UIColor.gray
// cell?.textLabel?.font = UIFont(name:"Swiss721BT-Roman", size: 8)
cell?.lbl.font = UIFont.systemFont(ofSize: 11)
return cell!
}
}
部分中的行数应该为致命错误更改:索引超出范围func tableView(_ tableView:UITableView,numberOfRowsInSection section:Int) - > Int {
if section == 0
{
return 0
}
// For section 1, the total count is items count plus the number of headers
var count = sections.count
//var sapna = data[section]
for section in sections
{
//count += data.count
count += section.items.count
//count += section.items.append(contentsOf: sapna.slug!)
}
return data.count
}