Ios 为什么tableview头是initWithCoder方法在重用头上调用的
我有一个带有标题的tableview 现在我注册了标题的nib,如下所示:Ios 为什么tableview头是initWithCoder方法在重用头上调用的,ios,uitableview,Ios,Uitableview,我有一个带有标题的tableview 现在我注册了标题的nib,如下所示: [tableView registerNib:[UINib nibWithNibName:[self layoutName] bundle:[NSBundle mainBundle]] forHeaderFooterViewReuseIdentifier:[self cellIdentifier]]; 在tableview控制器内部 这条线呢 MyCustomHeader *header = (MyCustomHead
[tableView registerNib:[UINib nibWithNibName:[self layoutName] bundle:[NSBundle mainBundle]] forHeaderFooterViewReuseIdentifier:[self cellIdentifier]];
在tableview控制器内部
这条线呢
MyCustomHeader *header = (MyCustomHeader*)[tableView dequeueReusableHeaderFooterViewWithIdentifier:[self cellIdentifier]];
始终返回非空单元格
我给表头的nib有几个自定义对象
调用dequeueReusableHeaderFooterViewWithReuseIdentifier
似乎调用了自定义对象的initWithCoder
如果单元应该被重用,而所有对象都已经“预先设置”了,为什么会这样呢
编辑打开/关闭代码
- (void)sectionHeaderView:(BaseSectionHeaderView *)sectionHeaderView sectionOpened:(NSInteger)sectionOpened {
LogInfo(@"opening section:%ld",sectionOpened);
if(self.openSection.openSectionHeaderView == sectionHeaderView){
[self sectionHeaderView:sectionHeaderView sectionClosed:sectionOpened];
LogInfo(@"this section is already open");
return;
}
[_purchaseDataSource setSectionAtIndex:sectionOpened Open:YES];
/*
Create an array containing the index paths of the rows to insert: These correspond to the rows for each quotation in the current section.
*/
NSInteger countOfRowsToInsert = 1;
NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < countOfRowsToInsert; i++) {
[indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:sectionOpened]];
}
/*
Create an array containing the index paths of the rows to delete: These correspond to the rows for each quotation in the previously-open section, if there was one.
*/
NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
if (self.openSection.openSectionHeaderView != nil) {
[_purchaseDataSource setSectionAtIndex:self.openSection.openSectionIndex Open:NO];
[_openSection.openSectionHeaderView toggleOpenWithUserAction:NO];
NSInteger countOfRowsToDelete = [_purchaseInvoiceListTable.tableView numberOfRowsInSection:self.openSection.openSectionIndex]; for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:self.openSection.openSectionIndex]];
}
}
// style the animation so that there's a smooth flow in either direction
UITableViewRowAnimation insertAnimation;
UITableViewRowAnimation deleteAnimation;
if (self.openSection.openSectionHeaderView == nil || sectionOpened < self.openSection.openSectionIndex) {
insertAnimation = UITableViewRowAnimationTop;
deleteAnimation = UITableViewRowAnimationBottom;
}
else {
insertAnimation = UITableViewRowAnimationBottom;
deleteAnimation = UITableViewRowAnimationTop;
}
// apply the updates
[_purchaseInvoiceListTable.tableView beginUpdates];
[_purchaseInvoiceListTable.tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:insertAnimation];
[_purchaseInvoiceListTable.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation];
[_purchaseInvoiceListTable.tableView endUpdates];
CGRect frame = sectionHeaderView.frame;
LogInfo(@"frame: %@",[NSValue valueWithCGRect:frame]);
[self scrollTableViewFromBottomAnimated:YES];
//
self.openSection.openSectionIndex = sectionOpened;
self.openSection.openSectionHeaderView = sectionHeaderView;
self.openSection.sectionHeight = [NSNumber numberWithFloat:sectionHeaderView.frame.size.height];
LogInfo(@"sectionOpened:%ld",sectionOpened);
}
- (void)sectionHeaderView:(BaseSectionHeaderView *)sectionHeaderView sectionClosed:(NSInteger)sectionClosed {
/*
Create an array of the index paths of the rows in the section that was closed, then delete those rows from the table view.
*/
[_purchaseDataSource setSectionAtIndex:sectionClosed Open:NO];
NSInteger countOfRowsToDelete = [_purchaseInvoiceListTable.tableView numberOfRowsInSection:sectionClosed];
if (countOfRowsToDelete > 0) {
NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:sectionClosed]];
}
[_purchaseInvoiceListTable.tableView beginUpdates];
[_purchaseInvoiceListTable.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
[_purchaseInvoiceListTable.tableView endUpdates];
}
self.openSection.openSectionIndex = NSNotFound;
self.openSection.openSectionHeaderView = nil;
LogInfo(@"sectionClosed:%ld",sectionClosed);
}
- (void)toggleOpenWithUserAction:(BOOL)userAction {
// toggle the disclosure button state
self.selected = !self.selected;
// if this was a user action, send the delegate the appropriate message
if (userAction) {
if (self.selected) {
if ([self.delegate respondsToSelector:@selector(sectionHeaderView:sectionOpened:)]) {
[self.delegate sectionHeaderView:self sectionOpened:self.section];
}
}
else {
if ([self.delegate respondsToSelector:@selector(sectionHeaderView:sectionClosed:)]) {
[self.delegate sectionHeaderView:self sectionClosed:self.section];
}
}
}
}
-(void)sectionHeaderView:(BaseSectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)sectionOpened{
登录信息(@“正在打开的节:%ld”,节已打开);
if(self.openSection.openSectionHeaderView==sectionHeaderView){
[自分段头视图:分段头视图:分段关闭:分段打开];
LogInfo(@“此部分已打开”);
返回;
}
[_PurchaseDataSourceSetSectionAtIndex:sectionOpened:YES];
/*
创建一个数组,其中包含要插入的行的索引路径:这些路径对应于当前节中每个引号的行。
*/
NSInteger ROWSTOINSERT计数=1;
NSMUTABLEARRY*indexPathsToInsert=[[NSMUTABLEARRY alloc]init];
对于(NSInteger i=0;i0){
NSMUTABLEARRY*indexPathsToDelete=[[NSMUTABLEARRY alloc]init];
对于(NSInteger i=0;i
似乎被调用了?那么您正在记录重用和init执行?是的(一个单词就足够了,但是注释需要很长),所以您永远不会看到头被重用?是否正在设置重用标识符?这是在反复滚动(超过2个创建)之后?我的tableview允许在我需要新标题之前在屏幕上显示4个标题,标题是可关闭的,这意味着,我可以关闭标题之间的行,以便只有标题。我正在记录自定义对象的initWithCoder,并且