Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView with custom cells draws fine on iOS 6 but completely white in iOS 7

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

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):

enter image description here

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

enter image description here

Here is the code for -(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;

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"];

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

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).

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.

like image 510
Can Poyrazoğlu Avatar asked Nov 21 '13 21:11

Can Poyrazoğlu


1 Answers

setcontentview backgroundColor to clear color

like image 170
Nate Avatar answered Oct 25 '22 04:10

Nate