TableViewで、データの表示をしたいだけで、特にタップ時のアクションなどを起こしたくない場合の設定。
- (void)viewDidLoad { //タップ時のハイライトをOFF self.tableView.allowsSelection = NO; [super viewDidLoad]; } //タップ時のアクションをコメントアウト //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath //{ //}
特定のセルだけタップを可能にして、他のセルのタップアクションはOFFにする場合の設定。
※例は、セクション0のセルはタップ可能、それ以外はタップ不可
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { //cellの作成時に、タップさせたいセルとそうじゃないセルを切り分け if (indexPath.section == 0) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; }else { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier]; //セル単位でタップ時のハイライトをOFF cell.selectionStyle = UITableViewCellSelectionStyleNone; } } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //タップ時のアクションで、ハイライトを設定したセルを切り分け if (indexPath.section == 0){ if (indexPath.row == 0) { //セクション0ロウ0の処理; } } }