[英]expanded table view cell
我想在每個單元格選擇的小視圖中打開更多信息,例如擴展能夠查看的單元格。我也正在抓屏。 我無法點綴此求助信息。該如何完成!
我正在使用下面的代碼,它工作正常,但如何顯示特定單元格位置的隱藏視圖
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Deselect cell
[tableView deselectRowAtIndexPath:indexPath animated:TRUE];
// Toggle 'selected' state
BOOL isSelected = ![self cellIsSelected:indexPath];
// Store cell 'selected' state keyed on indexPath
NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
[selectedIndexes setObject:selectedIndex forKey:indexPath];
// This is where magic happens...
[tbleLectures beginUpdates];
[tbleLectures endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
// If our cell is selected, return double height
if([self cellIsSelected:indexPath]) {
return kCellHeight * 2.0;
// return 44;
}
// Cell isn't selected so return single height
return kCellHeight;
}
您可以重新加載tableview以使其生效,也可以僅重新加載tableView:didSelectRowAtIndexPath:
的單元格:
// This is where magic happens...
[tbleLectures beginUpdates];
[tbleLectures reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPathOfYourCell] withRowAnimation:UITableViewRowAnimationNone];
[tbleLectures endUpdates];
如果要更改單元格的高度,則應重新加載表格視圖並使用
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
顯示/隱藏詳細信息視圖的委托方法
另一個邏輯是維護tableView的狀態,並根據tableView的狀態填充單元格。 tableView應該具有isSelectedCell / notSelected狀態。 如果選擇了tableView,則返回單元格的數量始終為+1(一個為明細單元格); 然后在選定的單元格之后插入詳細信息單元格。 為了維護選定單元格的索引,您可能需要類變量。
對於iOS中的此類工作,您需要有一些邏輯! 希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.