Iphone UITableViewCell背景视图上的UIButton
我使用两个框架来滑动TableView的UITableViewCells。它们是:DMSlidingCell和lslidingtableviewcell。 我试图在UITableViewCell(单元格消失时显示的视图)的背景视图中放置一个按钮,我成功地这样做了-按钮显示出来。但此按钮不是处于非活动状态,就是禁用单元格的滑动行为。 我想知道是怎么做的。我基本上是在自定义单元格类中这样做的:Iphone UITableViewCell背景视图上的UIButton,iphone,ios,objective-c,uitableview,Iphone,Ios,Objective C,Uitableview,我使用两个框架来滑动TableView的UITableViewCells。它们是:DMSlidingCell和lslidingtableviewcell。 我试图在UITableViewCell(单元格消失时显示的视图)的背景视图中放置一个按钮,我成功地这样做了-按钮显示出来。但此按钮不是处于非活动状态,就是禁用单元格的滑动行为。 我想知道是怎么做的。我基本上是在自定义单元格类中这样做的: -(void) addButtonToCell { UIButton* btn = [UIButt
-(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;
}
对可能出现的问题有什么看法吗?提前谢谢 试试看
[self.tableView.backgroundView addSubview:btn];
再见 试试看
[self.tableView.backgroundView addSubview:btn];
再见 为什么你要将按钮放在视图的背景而不是桌面视图的前面?@SimonePistecchia这是有原因的,背景视图是从滑动中“显示”出来的视图,也是添加按钮的视图。你尝试过[self.tableView.backgroundView addSubview:btn]@SimonePistecchia你的方法奏效了!添加一个答案,这样我就可以接受它!为什么你要将按钮放在视图的背景而不是桌面视图的前面?@SimonePistecchia这是有原因的,背景视图是从滑动中“显示”出来的视图,也是添加按钮的视图。你尝试过[self.tableView.backgroundView addSubview:btn]@SimonePistecchia你的方法奏效了!添加一个答案,这样我就可以接受它!