настоящего времени у меня кнопка в viewForFooterInSection
каждой секции, что при нажатии на увеличивает высоту строк 5-10 с высоты от 0 до высоты 65, как показано ниже:Как иметь разные высоты строк в каждом разделе 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 строк, а не только ту, где была нажата кнопка. Как я могу указать только раздел, где была нажата кнопка?
EDIT:
Я попытался следующие предложения и делать это, как показано ниже, но это вызывает сбой с ошибкой '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;
}
}
}
Вы не можете использовать один ivar '_hasPressedShowMoreButton'. Вам нужно следить за состоянием кнопки для всех разделов. – rmaddy
@rmaddy Ах, имеет смысл. Размышление о том, как я могу отслеживать состояние каждой соответствующей кнопки? – Ghobs