所以这是一个API。我有两个带有项目 id ( [projects][id]
- ids
) 和父母 ( [projects][parent][id]
- projectsParentIDs
) id 的字段。我在下面的方法中比较了这两个字段cellForRowAtIndexPath
。到目前为止一切顺利(我认为)。如果projectsParentID
索引 1id
与索引 0 相同,则缩进cell
. 但是这段代码正在缩进所有单元格。不止一个。我究竟做错了什么?
for index in 0...self.projectsParentIDs.count-1 {
if(ids[index] == projectsParentIDs[index]+1){
cell.indentationLevel = 1
cell.indentationWidth = 30
}
}
"projects":[
{
"id":22,
"name":"MND",
"created_on":"2015-04-17T15:41:10+02:00",
"updated_on":"2015-04-17T15:41:10+02:00"
},
{
"id":23,
"name":"MND child",
"parent":{
"id":22,
"name":"MND"
}
],
"created_on":"2015-04-18T11:28:12+02:00",
"updated_on":"2015-04-18T11:28:12+02:00"
func tableView(tableView: UITableView, indentationLevelForRowAtIndexPath indexPath: NSIndexPath) -> Int {
var indent: Int = 1
if(indexPath.section == 1){
for index in 0...self.projectsParentIDs.count-1 {
if(ids[index] == projectsParentIDs[index]+1){
indent = 1
return indent
}else{
indent = 0
return indent
}
}
}
return indent
}