0

これは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
}

プロジェクトのスクリーンショット 編集されたスクリーンショット

4

1 に答える 1

1

UITableView次のdelegate方法を使用してください。

optional func tableView(_ tableView: UITableView, indentationLevelForRowAtIndexPath indexPath: NSIndexPath) -> Int
于 2015-04-19T11:46:32.370 に答える