[swift] tableViewのセルを選択不可にする
目次
tableViewのセルを選択不可にする
View全体で選択を不可
self.tableView.allowsSelection = false
セル個別に選択不可
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath:indexPath)
if indexPath.row == 1 {
// セルの選択不可にする
cell.selectionStyle = UITableViewCellSelectionStyle.None
} else {
// セルの選択を許可
cell.selectionStyle = UITableViewCellSelectionStyle.Blue
}
return cell
}
func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
switch indexPath.row {
case 0:
return indexPath;
// 選択不可にしたい場合は"nil"を返す
case 1:
return nil;
default:
return indexPath;
}
}