我已经创建了一个UITableViewCell的子类。我的需求是当我点击单元格时,在单元格底部添加一个UIView并相应地调整单元格的高度。这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCell* cell = (MyCell *) [self.table cellForRowAtIndexPath:indexPath];
UIView * options = [[UIView alloc] initWithFrame:CGRectMake(0, cell.frame.size.height - 27, cell.frame.size.width, 27)];
UIButton* button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[options addSubview:button1];
UIButton* button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[options addSubview:button2];
UIButton* button3 = [UIButton buttonWithType:UIButtonTypeCustom];
[options addSubview:button3];
//did some layout calculation here to position the button
[cell addSubview:options];
}
这里有一个视频,可以说明问题。
我还尝试将单元格的accessoryView从我的自定义UIButton更改为普通的UITableViewCellAccessoryDisclosure,但是没有成功。
MyCell * cell = (MyCell *)[self.table cellForRowAtIndexPath:temp];
[cell.accessoryView removeFromSuperview];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
如果你好奇我在做什么,我正在尝试创建一个推特机器人uitableviewcell,在这里你可以按下单元格/行并呈现其他选项(转发等),同时它也以动画形式显示。