带有自定义单元格的UITableView在iOS 6上绘制得很好,但在iOS 7中完全是白色的 [英] UITableView with custom cells draws fine on iOS 6 but completely white in iOS 7

查看:87
本文介绍了带有自定义单元格的UITableView在iOS 6上绘制得很好,但在iOS 7中完全是白色的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Xcode 5上构建一个针对iOS 6 +的应用程序。

I am building an app on Xcode 5 that targets iOS 6+.

我在使用自定义单元格构建表格视图时遇到问题。有趣的是,它在今天更新到Xcode 5.0.2之前一直很好用(我不知道发生了什么变化)。我的表格视图之前确实绘制了纯白色(下面的屏幕截图),当我搞砸了iOS 7 SDK附带的白色导航栏样式(我也不知道它们如何也相互链接)。无论如何,当我从我的代码中删除了灯状态栏选项时,我的表视图用于正常绘制,尽管我有黑色状态栏。今天,在安装Xcode 5.0.2之后,我构建了相同的项目而没有更改任何代码,我的表视图现在在iOS 7(设备和模拟器)上绘制纯白色。当我切换到iOS 6时,它显示完美(设备和模拟器)。我已经尝试清理构建文件夹,清理派生数据文件夹,重新启动Xcode /模拟器/设备,但没有任何改变。此外,应用程序开始显示白色状态栏,在更新Xcode之前没有。我知道他们应该是无关紧要的,但我现在很难开发我的应用程序。单元格接收所有触摸事件,表格视图滚动,我在输出处获得所有 NSLog s,当我向下滚动时我可以看到滚动条。它只是不画画。我的自定义单元格中有自定义 drawRect:代码。看到 UITableViewCell自定义CG绘图iOS 7 分享UITableViewCell - backgroundView掩盖了我在drawRect中做的任何事情我评论说代码,但它没有帮助。以下是我在iOS 7上获得的内容(灰色选定单元格):

I'm having trouble building up my table view with custom cells. Interestingly, it was working great until I updated to Xcode 5.0.2 today (I have no idea what changed). My table view did draw plain white (screenshot below) before too when I messed with the white navigation bar style (I have no idea how they also link to each other either) that came with iOS 7 SDK. Anyway, when I removed the light status bar option from my code, my table view used to draw normally, though I have black status bar. Today, after installing Xcode 5.0.2, I've built the same project without changing any code, and my table view now draws plain white on iOS 7 (both device and simulator). When I switch to iOS 6, it displays perfectly (both device and simulator). I've tried cleaning the build folder, cleaning the derived data folder, restarting Xcode/simulator/device, but nothing has changed. Also, the app started to display white status bar which didn't before updating Xcode. I know that they should be irrelevant but I'm having hard time developing my app now. The cells receive all the touch events, the table view does scroll, I'm getting all the NSLogs at the output and I can see the scroll bar when I scroll down. It just doesn't draw. I had custom drawRect: code in my custom cells. After seeing UITableViewCell custom CG drawing iOS 7 and subclassed UITableViewCell - backgroundView covers up anything I do in drawRect I commented out that code, but it didn't help. Here is what I'm getting on iOS 7 (selected cell in gray):

这是iOS 6上的相同应用程序(隐私模糊文字/图片):

And here is the same app on iOS 6 (blurred text/images for privacy):

以下是的代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

MyFriendViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"friendTableCell"];
    if(!cell){
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MyFriendViewCell" owner:self options:nil] lastObject];
    }
    /* some code that sets text fields/images */
    [...]
    return cell;

我有一个XIB文件(只有一个对象,我的自定义单元格类)和一个对应的类细胞。我在开始时注册了我的单元格:

I have a XIB file (with only one object, my custom cell class) and a class corresponding to the cell. I've registered my cell in the beginning:

[self.tableView registerNib:[UINib nibWithNibName:@"MyFriendViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"friendTableCell"];

我检查了单元格方法,dequeue永远不会返回 nil

I've checked the cell in the method, dequeue never returns nil anyway.

更新:我也意识到我的应用程序在iOS 6上的这个屏幕上空闲时使用100%CPU(即使它正确运行)和iOS 7上。)

UPDATE: I've also realized that my app uses 100% CPU when idle on this screen on both iOS 6 (even though it runs correctly) and on iOS 7).

重要:这个问题已经得到解答了,但对于那些想知道 drawRect:的人来说,问题与此无关,我还在使用自定义 drawRect:,它完美无缺。

IMPORTANT: The question has been answered, but to any of you who were wondering about drawRect:, the problem had nothing to do with that, I'm still using custom drawRect: and it works perfectly.

推荐答案

setcontentview backgroundColor to clear color

这篇关于带有自定义单元格的UITableView在iOS 6上绘制得很好,但在iOS 7中完全是白色的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆