简体   繁体   English

UITableViewCell背景视图上的UIButton

[英]UIButton on UITableViewCell background view

I'm using two frameworks to slide UITableViewCells of the TableView. 我正在使用两个框架来滑动TableView的UITableViewCells。 Those are: DMSlidingCell and LRSlidingTableViewCell . 它们是: DMSlidingCellLRSlidingTableViewCell I'm trying to put a button in the background view of UITableViewCell (the view which is shown when the Cell disappears) and I succeed in doing so - the button shows up. 我试图在UITableViewCell的背景视图中放置一个按钮(当Cell消失时显示的视图),并且我成功了-按钮出现了。 But this button is either inactive or it disables the sliding behaviour of the cell. 但是此按钮要么无效,要么禁用单元格的滑动行为。 I'm wondering how is it done. 我想知道如何完成。 I'm basically doing this in the custom cell class: 我基本上是在自定义单元格类中这样做的:

-(void) addButtonToCell
{
    UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame = CGRectMake(95, 25, 60, 44);
    btn.tag = 1234;
    [btn setTitle:@"Hi" forState:UIControlStateNormal];
    [btn addTarget:self
            action:@selector(tryOut)
  forControlEvents:UIControlEventTouchDown];
    [self.backgroundView addSubview:btn];
}

And I add the button to the view like this: 然后将按钮添加到视图中,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *identifier = @"CELL_IDENTIFIER";

  LRSlidingTableViewCell *cell = (LRSlidingTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];

  if (cell == nil) {
    cell = [[[LRSlidingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
  }

  cell.selectionStyle = UITableViewCellSelectionStyleNone;
  cell.contentView.backgroundColor = [UIColor whiteColor];
  cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", indexPath.row];
  cell.delegate = self;
  [cell addButtonToCell];

  return cell;
}

Any ideas on what could be wrong? 有什么想法可能有问题吗? Thanks in advance! 提前致谢!

try 尝试

[self.tableView.backgroundView addSubview:btn];

see you! 再见!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM