6

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.

Community
  • 1
  • 1
Can Poyrazoğlu
  • 29,145
  • 40
  • 152
  • 327

2 Answers2

2

setcontentview backgroundColor to clear color

Kumar KL
  • 15,086
  • 9
  • 36
  • 57
Nate
  • 411
  • 4
  • 13
  • it's already clearColor, i had that problem before. it is set as `self.contentView.backgroundColor = [UIColor clearColor];` on all three init methods, and I've verified that it is still clear color when drawing by debugging. – Can Poyrazoğlu Nov 21 '13 at 21:42
  • check contentView cell.background, backgroundview – Nate Nov 21 '13 at 21:43
  • 1
    yeah, it was cell.backgroundColor. i've changed the initialization code to ` self.contentView.backgroundColor = [UIColor clearColor]; self.backgroundColor = [UIColor clearColor];` and it worked. any ideas why such a weird changed happened after updating to xcode 5.0.2 from 5.0.0? – Can Poyrazoğlu Nov 21 '13 at 21:47
  • i think iOS7 changed the way cells' default views are constructed – Nate Nov 21 '13 at 21:51
  • it's still interesting that the same thing didn't happen before in xcode 5.0.0 when I was still in iOS 7. – Can Poyrazoğlu Nov 21 '13 at 22:05
1

This answer by @Kjuly to a similar question is what I've used to fix this problem. The important part is to add this method to your table view's delegate:

- (void)tableView:(UITableView *)tableView
  willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
  [cell setBackgroundColor:[UIColor clearColor]];
}
Community
  • 1
  • 1
DarkDust
  • 85,893
  • 19
  • 180
  • 214