So this is an API. I have two fields with ids of projects ([projects][id]
- ids
) and ids of parents ([projects][parent][id]
- projectsParentIDs
). I compare these two fields in the method cellForRowAtIndexPath
like below. So far so good (I think). If projectsParentID
with index 1 is the same as id
with index 0, indent that cell
. But this code is indenting all cells. Not only the one. What am I doing wrong?
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
}