
思路:点击按钮时,改变旧cell、新cell高度,再重新加载指定行。
代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {if (_selectedIndexPath.isEqual(indexPath)) {
return BIG_HEIGHT // 展开后高度
} else {
return DEFAULT_HEIGHT // 默认高度
}
}
- (void)changeButtonClick:(id)sender {
NSIndexPath *indexPath = [self indexPathForButton:sender] // 需要自己实现
NSArray *indexPaths = _selectedIndexPath ? @[indexPath, _selectedIndexPath] : @[indexPath]
[self.tableView reloadRowsAtIndexPaths:indexPaths]
_selectedIndexPath = indexPath
}
点击的时候确定你的button足够大,点击相应的是button,而不是cell,因为cell本身也是有点击回调的。其次你要在每次调cell ForRowAtIndexPath方法里,
给cell的自定义属性赋值(比如你给cell定义了row属性)。然后在return cell。
如果你不重新赋值,那么因为cell的可重复利用性,某一行的cell再滚入屏幕时会重用上次回收该cell时的旧值。
根据tag值进行获取,在这里设置tag值,
然后在方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中进行获取这个tag值,获取方法是:
UIButton *exitBtn = (UIButton *)[cell viewWithTag:1]//1是我上面设置的tag值
这样就获取到了,你再给他添加action事件就可以了,
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)