2016-05-12 4 views
0

2つのセクションを持つテーブルビューがあります。セクション1の各セル(第2のセクション)は、タップアクセサリと、セクション1の別のセルがタップされたときの選択解除メソッドとを有する。しかし、セクション0のセルがタップされている場合、これも現在選択されているセルの選択を解除します。セクションの他のセルがタップされている場合にのみセルを選択解除します

私のコードがある:私はセル状部1内の他のセルが選択された場合に非選択と他の部分のために選択解除を無視するであろう

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    if(indexPath.section == 1) 
    { 
     tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .Checkmark 
    } 
} 

override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { 
    if(indexPath.section == 1) 
    { 
     tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .None 
    } 
} 

どのような考えですか?以下に示すように

答えて

0

は、適切な参照のために、あなたは、あなたのglobalArray自体内の参照を管理する必要があります。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    { 
    ......... 
    if (globalArray[indexpath.row][SELECTED_STATE] == SELECTED) 
    { 
    tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .Checkmark 
    } 
    else 
    { 
    tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = .None 
    } 
    ......... 


    } 
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

    //remove the pre selected state if needed by iterating the array 

    globalArray[indexpath.row][SELECTED_STATE] = SELECTED 

    tableView .reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None) 

} 
関連する問題