@blog.justoneplanet.info

日々勉強

UITableViewCellの中にUIButtonを配置する

btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTag:BTN];
[btn setFrame:CGRectMake(200, 5, 50, 50)];
[btn setTitle:@"t" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(onCellButtonPushed:event:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:btn];

以下のようにしてどのcellのボタンが押されたか判定する。

- (void)onCellButtonPushed:(UIButton *)button event:(id)event {
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
    if (indexPath != nil) {
    }
}

コメントはまだありません»

No comments yet.

RSS feed for comments on this post.TrackBack URL

Leave a comment