1

我正在使用两个框架来滑动 TableView 的 UITableViewCells。它们是:DMSlidingCellLRSlidingTableViewCell。我试图在 UITableViewCell 的背景视图中放置一个按钮(当 Cell 消失时显示的视图)并且我成功地这样做了 - 按钮出现了。但是这个按钮要么处于非活动状态,要么禁用单元格的滑动行为。我想知道它是如何完成的。我基本上是在自定义单元类中执行此操作:

-(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];
}

我将按钮添加到视图中,如下所示:

- (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;
}

关于什么可能是错误的任何想法?提前致谢!

4

1 回答 1

1

尝试

[self.tableView.backgroundView addSubview:btn];

再见!

于 2013-01-14T18:30:41.040 回答