5

そのボタンをクリックすると、すべてのテーブルビュー セルのアクセサリ タイプが に設定されるように、リセット ボタンをコーディングしようとしていますnone

私はそれを行う方法について明確な概念を持っていますが、私は iPhone 開発にかなり慣れていないので、どのメソッドを呼び出すかについて助けが必要です。

実行する必要があると思われる手順: for ループを使用してすべての行を反復処理しているため、セルの数を数えています (正常に完了しました)。私の問題は、アクセサリの種類が CheckMark である場合に、これらの行/セルのそれぞれをチェックして に設定する方法がわからないことnoneです。

別の方法として、すべてのセルを に設定することもできますがAccessoryNone、次の内部で既にいくつかの計算を行っています。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

したがって、どうすればこれを達成できるかわかりません。

4

2 に答える 2

12

が最初に何であるかを確認する必要はありません。それらすべてにaccessoryType割り当てるだけです。UITableViewCellAccessoryNoneこれは、あなたがやろうとしていることに対してうまくいくはずです:

// replace clickedResetButton with your action handler method for that button
- (IBAction)clickedResetButton:(id)sender {
    for (int section = 0, sectionCount = self.tableView.numberOfSections; section < sectionCount; ++section) {
        for (int row = 0, rowCount = [self.tableView numberOfRowsInSection:section]; row < rowCount; ++row) {
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.accessoryView = nill;
        }
    }
}
于 2011-11-20T23:05:45.143 に答える
2

スウィフト 3.1

func resetAccessoryType(){
    for section in 0..<self.tableView.numberOfSections{
        for row in 0..<self.tableView.numberOfRows(inSection: section){
            let cell = self.tableView.cellForRow(at: IndexPath(row: row, section: section))
            cell?.accessoryType = .none
        }
    }
}
于 2017-08-08T13:30:21.220 に答える