首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TableView titleForHeaderInSection

TableView titleForHeaderInSection
EN

Stack Overflow用户
提问于 2012-02-24 01:41:25
回答 1查看 5.6K关注 0票数 1

我的应用程序在4.3.1模拟器中显示了这一点,在5.0模拟器中显示了这一点。

代码如下:

代码语言:javascript
复制
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
   return @""; 
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[Singleton sharedInstance] getTitleSectionView:segmentedControl.selectedSegmentIndex inDay:section];
}
-(UIView *)getTitleSectionView:(int)week inDay:(int)day;
{
UILabel *lab=[[[UILabel alloc]init]autorelease];
lab.frame=CGRectMake(5, 0,320,20);
lab.text=[[Singleton sharedInstance] getTitleSection:week inDay:day];
lab.backgroundColor=[UIColor clearColor];
lab.textColor=[UIColor whiteColor];
lab.font = [UIFont fontWithName:@"Arial" size:14];

UIImageView * imv = [[[UIImageView alloc]initWithFrame:CGRectMake(0,0, 320, 20)]autorelease];
imv.image=[UIImage imageNamed:@"section-header-bg.png"];

UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]autorelease];
[view addSubview:imv];
[view addSubview:lab];

    Week *currentWeek = nil;
    if(week)    
        currentWeek = nechetNedel;
    else        
        currentWeek = chetNedel;

    NSMutableArray *dayArray = [currentWeek.days objectAtIndex:day];
    if([dayArray count] >0)
        return view;
    return nil;
}

这可能是什么问题,为什么在5.0模拟器中会出现一行行的部分?我试图删除方法- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section,但它没有帮助。我删除了这个方法(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section,这几行就消失了

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-24 02:07:50

对于空节,应返回nil

代码语言:javascript
复制
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

代码语言:javascript
复制
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

应返回0

那么它就会起作用。这是iOS 5.x问题(或功能)

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9418240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档