「オン」のチェックマークを「オフ」に変更するには、とのCellAccessoryType
間を変更する必要があると考えてよろしいですか?none
checkmark
didSelectRowAtIndexPath
私はこれを行ったが、動作がiPhoneの自動ロック設定のチェックマークセルのように完全に同一ではないことに気付いた.
または、チェックマークを処理するための他の方法はありますか?
「オン」のチェックマークを「オフ」に変更するには、とのCellAccessoryType
間を変更する必要があると考えてよろしいですか?none
checkmark
didSelectRowAtIndexPath
私はこれを行ったが、動作がiPhoneの自動ロック設定のチェックマークセルのように完全に同一ではないことに気付いた.
または、チェックマークを処理するための他の方法はありますか?
selectedRow
テーブル セクションでチェックされた項目を表す行のインデックスを表すというビュー コントローラーのプロパティを保持します。
ビュー コントローラーの-tableView:cellForRowAtIndexPath:
デリゲート メソッドで、セルの値が等しい場合accessoryType
にを設定します。それ以外の場合は、に設定します。cell
UITableViewCellAccessoryCheckmark
indexPath.row
selectedRow
UITableViewCellAccessoryNone
ビュー コントローラの-tableView:didSelectRowAtIndexPath:
デリゲート メソッドで、selectedRow
値をindexPath.row
選択されているものに設定します。次に例を示します。self.selectedRow = indexPath.row
別の解決策:
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *oldIndex = [self.tableView indexPathForSelectedRow];
[self.tableView cellForRowAtIndexPath:oldIndex].accessoryType = UITableViewCellAccessoryNone;
[self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
return indexPath;
}
そしてええ:そうかどうかを確認する必要はありませoldIndex
んnil
:)
Swift 3 以降:
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
if let oldIndex = tableView.indexPathForSelectedRow {
tableView.cellForRow(at: oldIndex)?.accessoryType = .none
}
tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
return indexPath
}
迅速:
var selectedCell:UITableViewCell?{
willSet{
selectedCell?.accessoryType = .None
newValue?.accessoryType = .Checkmark
}
}
それから:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedCell = self.tableView.cellForRowAtIndexPath(indexPath)
self.mapView.selectAnnotation(self.mapView.annotations[indexPath.row], animated: true)
}
そのはず
didHighlightRowAtIndexPath
それ以外の
tableView:didSelectRowAtIndexPath
アレックスの答えは、 reload table を .hに追加した後にのみ機能しました
{
int selectedCell;
}
@property(nonatomic,readwrite)int selectedCell;
in .m * cellForRowAtIndexPath *
if(indexPath.row == selectedCell)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.selected = YES;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selected = NO;
}
そしてどこでも didHighlightRowAtIndexPath または didSelectRowAtIndexPath
self.selectedCell = indexPath.row;
[self.tableView reloadData];