【问题标题】:TableView titleForHeaderInSectionTableView 标题ForHeaderInSection
【发布时间】:2012-02-24 02:20:41
【问题描述】:

我的应用在 4.3.1 模拟器中显示此内容                 并在 5.0 模拟器中显示此内容。

这是代码:

- (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,线条消失了

【问题讨论】:

  • 告诉我们numberOfSectionsInTableView:
  • - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 7; }
  • 现在计算 iOS 5 sim 中褐色和灰色的标题。你明白了吗?
  • Matthias Bauch 我不太明白
  • rokjarc 我无法更正节数,例如我在第 4 节中有数据,但返回 1 个计数,表中将是第​​一节

标签: iphone objective-c ios


【解决方案1】:

你应该为空部分返回 nil

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

应该返回 0

然后它将起作用。这是 iOS 5.x 问题(或功能)

【讨论】:

  • - (UIView *)tableView: 这里我返回 nil 并且标题的图像不显示,但显示灰线, - (CGFloat)tableView: 如果这里我返回 0。我没有看到图像这个方法的 - (UIView *)tableView:
  • 它可以工作,但是为什么在IOS 4.3之前它可以工作,而在5.0不能工作,我无法理解
  • 如果您不明白,请阅读文档。 iOS 5.0 的发行说明清楚地指出了这一点:“[在 iOS 5] 从 tableView:viewForHeaderInSection: 方法(或其等效页脚)返回 nil 不再足以隐藏标题。您必须覆盖 tableView:heightForHeaderInSection:并返回 0.0 以隐藏标题。”
猜你喜欢
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 2016-04-12
  • 2012-06-27
  • 2015-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多