我现在有在该按钮时每个部分的viewForFooterInSection
一个按钮,从0至65的高度的高度增加的行5-10的高度,如下所示:如何在UITableView的每个部分有不同的行高?
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.backgroundColor = [UIColor whiteColor];
self.moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.moreButton.frame = CGRectMake(0, 0, 320, 44);
[self.moreButton setImage:[UIImage imageNamed:@"downarrow.png"] forState:UIControlStateNormal];
[self.moreButton addTarget:self action:@selector(moreButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:self.moreButton];
return view;
}
- (void)moreButtonSelected:(id)sender {
if (_hasPressedShowMoreButton == NO){
self.hasPressedShowMoreButton = YES;
}
else if (_hasPressedShowMoreButton == YES){
self.hasPressedShowMoreButton = NO;
}
[self.matchCenter reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_hasPressedShowMoreButton == YES){
return 65;
}
else if (_hasPressedShowMoreButton == NO){
if (indexPath.row > 3){
return 0;
}
else{
return 65;
}
}
}
这就意味着是“显示更多”类型的动作,这样当按下时,其余行将出现,而不是仅前4个。问题是,当按下某个节的页脚中的按钮时,它会展开所有部分到10行,而不仅仅是按下按钮的那一行。我怎样才能指定按钮被按下的部分?
编辑:
我试过以下的建议,并做如下图所示,但它引发的崩溃与错误'NSInvalidArgumentException', reason: '-[UIButton section]: unrecognized selector sent to instance 0x7f94840640b0'
。
代码:
- (void)moreButtonSelected:(NSIndexPath *)indexPath{
if (_hasPressedShowMoreButton == NO){
self.hasPressedShowMoreButton = YES;
indexPath.section == _expandedSection;
}
else if (_hasPressedShowMoreButton == YES){
self.hasPressedShowMoreButton = NO;
}
[self.matchCenter reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_hasPressedShowMoreButton == YES){
if (indexPath.section == _expandedSection){
return 65;
}
}
else if (_hasPressedShowMoreButton == NO){
if (indexPath.row > 3){
return 0;
}
else{
return 65;
}
}
}
您不能使用单个法尔'_hasPressedShowMoreButton'。您需要跟踪所有部分的按钮状态。 – rmaddy 2014-10-07 17:30:59
@rmaddy啊,有道理。介绍如何跟踪每个按钮的状态? – Ghobs 2014-10-07 17:33:34