これはAPIです。[projects][id]
プロジェクトの ID ( - ids
) と親の ID ( [projects][parent][id]
- )を持つ 2 つのフィールドがありますprojectsParentIDs
。以下のようなメソッドでこれら2つのフィールドを比較しcellForRowAtIndexPath
ます。ここまでは順調です(と思います)。projectsParentID
インデックス 1 がインデックス 0 と同じ場合は、id
それをインデントしcell
ます。しかし、このコードはすべてのセルをインデントしています。1つだけではありません。私は何を間違っていますか?
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
}