大佬教程收集整理的这篇文章主要介绍了ios – 在UITableView中只调用一次viewForHeaderInSection,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个UITableView,表示25个(比方说)对象,每个对应25个部分,每行1行.
我正在创建的自定义单元格显示正常(所有25个,按正确顺序).我想在每个对象上方显示一个节头视图.
明智的NSLogging告诉我,只有一次调用viewForHeaderInSection,尽管每个对象调用heightForHeaderInSection 2x.我从numberOfSectionsInTableView返回25,从numberOfRowsInSection返回1.
我通过执行UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0,320,viewHeight)]然后添加UILabel和UIButton在viewForHeaderInSection中构建UIView.我不是UITableViewHeaderFooterView的子类.不确定这是否有所不同.
有任何想法吗?
相关代码:
部分和行数:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [self.objects count]; } - (NSInteger)numberOfRowsInSection:(NSInteger)section { return 1; }@H_262_24@行的高度和单元格:
- (CGFloat)tableView:(UITableView *)tableView heightForRowATindexPath:(NSIndexPath *)indexPath { return 390; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath object:(PFObject *)object { static NSString *CellIdentifier = @"Customcatell"; Customcatell *cell = (Customcatell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // add custom content to cell return cell; }@H_262_24@标题的高度和视图:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 60; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { NSLog(@"in viewForHeaderInSection %ld",(long)section); // I only see this once NSLog(@"return view for section %ld",section); // this is 0 when I see it // gather content for header UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,viewHeight)]; // add content to header (displays correctly) return headerView; }@H_262_24@
以上是大佬教程为你收集整理的ios – 在UITableView中只调用一次viewForHeaderInSection全部内容,希望文章能够帮你解决ios – 在UITableView中只调用一次viewForHeaderInSection所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。