Ios 为什么表中的第一节标题不显示?
我不明白为什么第一节标题没有显示。第二个和第三个显示良好。我怀疑是因为搜索栏 我试过像中那样将整张桌子偏移,但我没有注意到它偏移了Ios 为什么表中的第一节标题不显示?,ios,uitableview,Ios,Uitableview,我不明白为什么第一节标题没有显示。第二个和第三个显示良好。我怀疑是因为搜索栏 我试过像中那样将整张桌子偏移,但我没有注意到它偏移了 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { // create the parent view that will hold header Label UIView* customView = [[UIView a
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0,-60,300,60)];
// create the label object
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.frame = CGRectMake(0,0,self.view.frame.size.width,60);
UIColor* mainColor = [UIColor colorWithRed:47.0/255 green:168.0/255 blue:228.0/255 alpha:1.0f];
headerLabel.backgroundColor = mainColor;
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.textAlignment = UITextAlignmentCenter;
if(section == 0)
headerLabel.text = @"Friends";
if(section == 1)
headerLabel.text = @"Second Section Header";
if(section == 2)
headerLabel.text = @"Third Section Header";
headerLabel.textColor = [UIColor whiteColor];
[customView addSubview:headerLabel];
return customView;
}
- (void) hideSearchBar
{
self.feedTableView.contentOffset = CGPointMake( 0, self.searchBar.frame.size.height );
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//Number of rows it should expect should be based on the section
NSDictionary *dictionary = [_imageDataArray objectAtIndex:section];
NSArray *array = [dictionary objectForKey:@"data"];
return [array count];
}
你的代码中有一个bug。您的标题在那里,但它设置为高度为60的
y=-60
替换:
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0,-60,300,60)];
用这个
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,300,60)];
这是屏幕截图
希望这会有所帮助。它没有显示出来,因为我没有执行“头部高度”部分 详情如下:
在我的例子中,我需要在代码中显式地分配委托,即使委托已经在XIB文件中连接
tableView.delegate = self
tableView.dataSource = self
谢谢这确实是一个错误。但修复它并不能解决问题。请重新校对您的代码。如果设置了任何约束,请查看它。事实上,我也在使用相同的代码&它工作得很好。请查看我的答案所附的更新屏幕。它对我来说非常适合。您是否更改了任何约束或任何?无约束。当我把搜索栏从故事板的表格中拿出来/放在上面时,我可以看到标题的空格,但它是空白的…搜索栏的层次结构可以像现在这样吗?是的,我只设置了这样的层次结构。我讨厌苹果的这些“错误”。。。之前没有问题,然后,为什么只针对第一行…并确保返回类型为CGFloat。如果返回类型为NSInteger,则会出现奇怪的错误。