部分的UITableView头仅在滚动时出现
问题描述:
我在iPad上有一些奇怪的行为,我没有在iPhone上获得。部分的UITableView头仅在滚动时出现
我有一个分区表视图,有部分和标题的部分,问题是,在iPad上最顶端的部分的标题不显示,当向下滚动表的部分标题出现一小会儿之前屏幕。
之前滚动
滚动
的代码创建部分的标题后:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil || [sectionTitle isEqualToString:@""]) {
return nil;
}
// Create label with section title
UILabel *label = [[UILabel alloc] init] ;
label.frame = CGRectMake(12, 0, 300, 30);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0.0, 1.0);
label.font = [UIFont boldSystemFontOfSize:16];
label.text = sectionTitle;
UIImage *img = [UIImage imageNamed:@"header"];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];
imgView.image = img;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 44)];
[view addSubview:imgView];
[view addSubview:label];
return view;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
int aSection = [[self.sectionsToDisplay objectAtIndex:section] integerValue];
return [self.groupHeadings objectAtIndex:aSection];
}
我的TableView代码:
tableViewResult = [[UITableView alloc] initWithFrame:mainView.frame style:UITableViewStyleGrouped];
tableViewResult.separatorColor = [UIColor clearColor];
[mainView addSubview:tableViewResult];
我的任何数据加载到表之前设置的另一种方法的委托和数据源,因为我首先做一个网络请求,即当Web请求做我做的:
tableViewResult.delegate = self;
tableViewResult.dataSource = self;
[tableViewResult reloadData];
一切正常如预期的那样,除了最上面部分的标题,并且仅在iPad上。
任何想法可能导致此行为?
答
什么固定的问题是改变这一功能:
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
int aSection = [[self.sectionsToDisplay objectAtIndex:section] integerValue];
if([[self.groupHeadings objectAtIndex:aSection] isEqualToString:@""])
return nil;
return [self.groupHeadings objectAtIndex:aSection];
}
你如何创建的TableView,从界面生成器或代码?标题的高度是多少?你可以上传截图吗? –
我从代码构建它,会上传截图。 – Armand
您是否写过节的方法? – Mangesh