为UITableViewCell增加按钮及处理按钮事件的方法

来源:互联网 发布:淘宝网九块九包邮女装 编辑:程序博客网 时间:2024/06/11 09:19
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath{    UIImage *image = [UIImage imageNamed:@"test.png"];    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];    CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);    button.frame = frame;    [button addTarget:self action:@selector(accessoryViewButtonClicked:) forControlEvents:UIControlEventTouchUpInside];    [button setBackgroundImage:image forState:UIControlStateNormal];    cell.accessoryView = button;}

根据按钮的位置获得行数:
- (void)accessoryViewButtonClicked:(id)sender{    CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.tableView];    NSIndexPath *hitIndex = [self.tableView indexPathForRowAtPoint:hitPoint];    //...}
原创粉丝点击