У меня есть ячейки, которые расширяются, изменяя их высоту.Как увеличить высоту ячейки зависит от содержимого ячейки?
Я хочу открыть дополнительную информацию, такую как небольшой вид каждого выбора ячейки, расширяющая ячейку просмотра таблицы.
Мы выбрали ячейку, которую нужно развернуть и закрыть, когда мы снова щелкнем.
Я использую ниже код, он работает нормально, но как показать скрытый вид на конкретную позицию ячейки.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// UILabel *label = nil;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
// cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] ;
}
StudentClass *student = (StudentClass *) [arrayitems objectAtIndex:indexPath.row];
//If this is the selected index then calculate the height of the cell based on the amount of text we have
if(selectedIndex == indexPath.row)
{
UILabel *cellLabeltotaldays12=[[UILabel alloc]initWithFrame:CGRectMake(520, 80, 100, 12)];
cellLabeltotaldays12.font =[ UIFont systemFontOfSize:14];
cellLabeltotaldays12.text=student.totaldays;
[cell addSubview:cellLabeltotaldays12];
}
else {
//Otherwise just return the minimum height for the label.
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//The user is selecting the cell which is currently expanded
//we want to minimize it back
if(selectedIndex == indexPath.row)
{
selectedIndex = -1;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
return;
}
//First we check if a cell is already expanded.
//If it is we want to minimize make sure it is reloaded to minimize it back
if(selectedIndex >= 0)
{
NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
selectedIndex = indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];
}
//Finally set the selected index to the new selection and reload it to expand
selectedIndex = indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
Попробуйте эти ссылки: http://stackoverflow.com/questions/19855832/expanding-and-collapsing-table-view-cells-in-ios HTTP: //stackoverflow.com/questions/4635338/uitableviewcell-expand-on-click http://stackoverflow.com/questions/15109099/expand-uitableview-cell-in-uitableviewstyleplain –
Эй у вас искать первый в Google. По этой теме есть много решений. как один URL-адрес, который доступен в stackoverflow, точно соответствует вашему взгляду. http://stackoverflow.com/questions/19855832/expanding-and-collapsing-table-view-cells-in-ios – Thukaram