UITableView with custom cells great for iOS 6, but completely white in iOS 7

I am creating an application on Xcode 5 that is for iOS 6+.

I'm having trouble creating a table view using custom cells. Interestingly, it worked fine until I upgraded to Xcode 5.0.2 today (I don't know what changed). In my view of the table, I drew a plain white one (screenshot below) before I messed up with the white navigation style (I have no idea how they are also related to each other) that comes with the iOS 7 SDK. Anyway, when I removed the line status indicator from my code, my table view was used to draw normally, although I have a black status bar. Today, after installing Xcode 5.0.2, I built the same project without changing any code, and now my tabular view looks white on iOS 7 (both on the device and on the simulator). When I switch to iOS 6, it displays perfectly (both the device and the simulator). I tried to clear the build folder, clear the derived data folder, restart Xcode / simulator / device, but nothing changed. In addition, the application began to display a white status bar, which was not before the Xcode update. I know that they should be irrelevant, but now it’s difficult for me to develop an application. Cells receive all touch events, the view of the table scrolls, I get all the NSLog in the output, and I can see the scroll bar when scrolling down. He just does not draw. I had custom drawRect: code in my custom cells. After viewing a custom CG drawing of UITableViewCell iOS 7 and a subclass of UITableViewCell - backgroundView closes everything I do in drawRect I commented out from this code, but that didn't help. Here is what I get on iOS 7 (highlighted cell in gray):

enter image description here

And here is the same application on iOS 6 (blurry 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 own cell class) and a class corresponding to the cell. I registered my cell at the beginning:

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

I checked cell in a method, dequeue never returns nil anyway.

UPDATE: I also realized that my application uses a 100% processor when it works on this screen both on iOS 6 (although it works correctly) and on iOS 7).

IMPORTANT: The question was answered, but to any of you who wondered about drawRect: problem had nothing to do with it, I still use custom drawRect: and it works fine.

+6
source share
2 answers

setcontentview backgroundColor to clear color

+2
source

This answer from @Kjuly to a similar question is what I used to solve this problem. The important part is to add this method to the table view delegate:

 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cell setBackgroundColor:[UIColor clearColor]]; } 
+1
source

Source: https://habr.com/ru/post/958598/


All Articles