UITableViewCellはメモリ節約のためにインスタンスを使いまわしているので、スクロール時に新しいセルが読み込まれる都度、値を設定し直さないと、8個おきくらいで同じセルが表示されてしまいます。
例えば、次のようにプロパティに値を保持・読み込むようにすれば、問題なく動作するようになります。
// チェックされたセルの位置を保存しておく辞書をプロパティに宣言
var selectedCells:[String:Bool]=[String:Bool]()
// スクロールして読み込んだ時に、チェックマークの状態を設定し直す
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.selectMemberTableView.dequeueReusableCellWithIdentifier("SelectMemberTableViewCell") as! SelectMemberTableViewCell
let key = "\(indexPath.section)-\(indexPath.row)"
if let selected = selectedCells[key]{
cell.accessoryType=UITableViewCellAccessoryType.Checkmark
}else{
cell.accessoryType=UITableViewCellAccessoryType.None
}
return cell
}
// セルをタップした時に、チェックマークを切り替える処理・辞書にチェックマークの状態を保存する処理
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath) {
var _cell=tableView.cellForRowAtIndexPath(indexPath)
if let cell=_cell{
let key = "\(indexPath.section)-\(indexPath.row)"
if cell.accessoryType == UITableViewCellAccessoryType.None{
cell.accessoryType=UITableViewCellAccessoryType.Checkmark
selectedCells[key]=true;
}else{
cell.accessoryType=UITableViewCellAccessoryType.None
selectedCells.removeValueForKey(key)
}
}
}
参考: http://stackoverflow.com/questions/15610641/accessory-type-repeats-for-the-reused-cells-in-uitable-view


