简体   繁体   English

UITableView在IOS7中可见,但在IOS6中不可见

[英]UITableView visible in IOS7 but not visible in IOS6

I have a UIScrollView with a small UITableView inside. 我有一个带有小UITableViewUIScrollView In iOS-7 everything works perfectly, but in iOS-6 the table view does not show at all, completely invisible. iOS-7一切工作正常,但在iOS-6 ,表格视图完全不显示,完全不可见。 Everything is instantiated, the delegate and data source methods are called, but the UITableView just not appears. 一切都实例化,调用了委托和数据源方法,但没有出现UITableView A blank space and nothing else. 一个空白,没有别的。

Anyone has any idea why this might be happening? 任何人都不知道为什么会这样吗?

Update: 更新:

It's just the native UITableView with the native cells. 它只是带有本地单元格的本地UITableView。

Here's some example code: 这是一些示例代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_gridTableData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *gridCellId = @"gridCellID";

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:gridCellId];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:gridCellId];
        [cell.textLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:12]];
        [[cell textLabel] setText:_gridTableNames[[indexPath row]]];
        [cell.detailTextLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:12]];
        [[cell detailTextLabel] setText:_gridTableData[[indexPath row]]];
    }

    return cell;
}

Keep in mind that in iOS 7, by default, the background of cells is white. 请记住,在iOS 7中,默认情况下,单元格的背景为白色。 In 6 and earlier it's transparent. 在6及更早版本中它是透明的。 This means that if you have black text in a table that overlays a black background it will be invisible in 6 and earlier. 这意味着,如果表中的黑色文本与黑色背景重叠,则在6及更低版本中将不可见。 (Seeing some screen shots would help.) (查看一些屏幕快照会有所帮助。)

After some recommended log statements, I've found where's the problem: 在一些推荐的日志语句之后,我发现了问题所在:

In iOS6 the height of the UITableView's frame turns to 0. During "viewDidLoad" the height is correct(94p), but after that the height is always 0. 在iOS6中,UITableView框架的高度变为0。在“ viewDidLoad”期间,高度为正确(94p),但此后高度始终为0。

But I really don't know why this is happening. 但是我真的不知道为什么会这样。 In iOS7 the UITableView's height never changes. 在iOS7中,UITableView的高度永远不会改变。

So I can "fix" it by re-setting the UITableView's frame height in "viewDidLayoutSubviews", for example. 因此,例如,可以通过在“ viewDidLayoutSubviews”中重新设置UITableView的框架高度来“修复”它。 But if anyone has a clean way of fixing this, or knows the origin of this behaviour, it will be appreciated. 但是,如果任何人都有解决此问题的干净方法,或者知道此行为的起源,我们将不胜感激。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM