2014年4月19日土曜日

【Objective-C】UITableViewのEditMode(編集モード)時に行をすべて選択する方法

テーブルのセクションが1つの場合のサンプルプログラムです。テーブルの行を配列に取得して、各行に対してselectRowAtIndexPathでセクション(このサンプルでは0固定)と行番号を指定します。


■画面イメージ





//表示されている行のみチェックする場合
- (IBAction)btnMarkAll:(id)sender{
    NSArray *indexPaths = [self.tableView indexPathsForVisibleRows];
    for(NSIndexPath *indexPath in indexPaths){
        [self.tableView selectRowAtIndexPath:
         [NSIndexPath indexPathForRow:indexPath.row inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
    }
}

すべてをチェックする場合はtableデータソースである配列を指定してまわせばできます。
//MarkAllボタン
- (IBAction)btnMarkAll:(id)sender{
    for (int i = 0; i < [_tableKey count]; i++) {
        [self.tableView selectRowAtIndexPath:
         [NSIndexPath indexPathForRow:i inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
    }

}





0 件のコメント:

コメントを投稿