Custom Cellを用いたTableViewを実装しております。
Custom Cellの親Viewのタッチイベントを無効にし、子ViewのButtonのみにタッチイベントを有効にしたいと思っています。
現状は添付しました画像のように親ViewにタッチイベントでCellの色が変わってしまう状態です。
ContentView ParentView Button
というレイヤになっています。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { AccountingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:REUSE_IDENTIFER]; if (!cell){ cell = [[AccountingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:REUSE_IDENTIFER]; } // イベントを付ける [cell.buyButton addTarget:self action:@selector(handleTouchButton:event:) forControlEvents:UIControlEventTouchUpInside]; // Configure the cell... cell.accessoryType = UITableViewCellAccessoryNone; return cell; }
上記のようにCellを初期化しております。
// UIControlEventからタッチ位置のindexPathを取得する - (NSIndexPath *)indexPathForControlEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint p = [touch locationInView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p]; return indexPath; }
上記のようにタッチ位置を取得しております。
親Viewのイベントを無くし、子ViewのButtonのみにイベントを付ける良い手段はありますでしょうか?
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/08/17 09:26