Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
This problem is only in ios7. I have 2 photos included that show my problem. It looks as it should in IOS 6 but I have white backgrounds in IOS 7.

I attempted to add some code that checked the system version and add a UIColor clearColor if the version was 7.0 but the cells are still white.

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    cell.textLabel.font = [UIFont fontWithName:@"Papyrus" size:26];
    cell.textLabel.textColor = [UIColor blackColor];
    
    if (tableView == characterListTableView) {
        
        if (indexPath.row == 0) {
            cell.textLabel.textAlignment = UITextAlignmentCenter;
        }
        
        cell.textLabel.text = [characterArray objectAtIndex:indexPath.row];

        [COLOR="Red"]if (deviceVersion == 7.0) {
            cell.textLabel.backgroundColor = [UIColor clearColor];
        }[/COLOR]
    }
    
    else if (tableView == foundTV){
        cell.textLabel.textAlignment = UITextAlignmentCenter;
        cell.textLabel.text = [foundFiles objectAtIndex:indexPath.row];
    }

    return cell;
}

Nothing seems to be depreciated that I can see that would cause this problem.
Just in case the issue with the creation of the tableView it's self that is causing the problem the code is below.

Code:
characterListTableView = [[UITableView alloc] initWithFrame:CGRectMake(675, 165, 272, 388) style:UITableViewStylePlain];
    characterListTableView.dataSource = self;
    characterListTableView.delegate = self;
    characterListTableView.backgroundColor = [UIColor clearColor];
    characterListTableView.separatorColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
    characterListTableView.opaque = NO;
    characterListTableView.backgroundView = nil;
    [characterListTableView.layer setBorderColor: [[UIColor blackColor] CGColor]];//set black boarder around notefield
    [characterListTableView.layer setBorderWidth: 2.0];//set black boarder thikness
    
    CALayer * btv = [characterListTableView layer]; // rounds the edges of the noteField
    [btv setMasksToBounds:YES];
    [btv setCornerRadius:10.0];
    
    [self.view addSubview:characterListTableView];
    
    UIImage *imagePaper = [UIImage imageNamed:@"scroll_paper.png"];
    [tableViewWhiteWash setImage:imagePaper];
    tableViewWhiteWash.alpha = 0.5;
    
    //[tableViewWhiteWash setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5]];
    CALayer * bvbg = [tableViewWhiteWash layer]; // rounds the edges of the noteField
    [bvbg setMasksToBounds:YES];
    [bvbg setCornerRadius:10.0];
    
    [tableViewImportWhiteWash setImage:imagePaper];
    tableViewImportWhiteWash.alpha = 0.0;
    CALayer * bvim = [tableViewImportWhiteWash layer]; // rounds the edges of the noteField
    [bvim setMasksToBounds:YES];
    [bvim setCornerRadius:10.0];

Thanks.
 

Attachments

  • Screen Shot 2013-10-01 at 5.40.30 PM.png
    Screen Shot 2013-10-01 at 5.40.30 PM.png
    192.1 KB · Views: 482
  • Screen Shot 2013-10-01 at 5.44.08 PM.png
    Screen Shot 2013-10-01 at 5.44.08 PM.png
    210.4 KB · Views: 408

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
Looks to me like you need to set up the cell with clear color. Such as this;

Code:
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    [COLOR="Blue"]// Since these never change, place these two lines in the cell initialization.[/COLOR]   
    cell.textLabel.font = [UIFont fontWithName:@"Papyrus" size:26]; 
    cell.textLabel.textColor = [UIColor blackColor];

    [COLOR="Red"]cell.contentView.backgroundColor = [UIColor clearColor];[/COLOR]
}

I also noticed that the separator lines under iOS 7 are not left justified. I don't see an obvious reason.
 
Last edited:

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
@OP, you may need to set the background colors in the willDisplayCell: delegate callback.

@xStep, the obvious reason is that Apple wants it that way. This is one of the iOS 7 appearance changes for UITableView. It is controllable with a separatorInset property.
 

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
EDIT: I discovered the problem in another search. I don't need to access the cell.textLabel.backgroundColor or the cell.contentView.backgroundColor. I just needed to say

Code:
 cell.backgroundColor = [UIColor clearColor];
I don't know why I can just address the cell and not the contentView or textLabel attribute?

-------
I have never used that delegate method before. I set break points and it seems that I sets the cell up first and returns in and then this method is called. So the indexPath is passed to it and it uses a pointer to the cell.

It would seem the only thing I would need to do is to change the color of the background to clear but it is not work, the results are the same with a white background instead of clear. I'm guessing, because i'm not 100% sure, that if I add a background color someplace like where the cell is created it would be changed by this method?

I am a little fuzzy as to the difference between the cell.contentView.backgroundColor and the cell.textLable.backgroundColor. I can google that and find out.

The code seems to be simple but I must be over looking something else

Code:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    cell.contentView.backgroundColor = [UIColor clearColor];

}

I also tried the cell.textLabel.backgroundColor and none worked. The method is being called and I tested it with an NSLog to verify that.
 
Last edited:

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
@xStep, the obvious reason is that Apple wants it that way. This is one of the iOS 7 appearance changes for UITableView. It is controllable with a separatorInset property.

EDIT: You are right. If you use the SDK 7 then you get the indent. JUST WOW!

EDIT2: WOW, what a CF!
 
Last edited:

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
EDIT: I discovered the problem in another search. I don't need to access the cell.textLabel.backgroundColor or the cell.contentView.backgroundColor. I just needed to say

Code:
 cell.backgroundColor = [UIColor clearColor];
I don't know why I can just address the cell and not the contentView or textLabel attribute?

Watch out with that one. If the target is 6.x, you'll alter the label background color. If the target is 7.0 you'll alter the expected rectangle. In both cases I was altering the value within tableView:willDisplayCell:forRowAtIndexPath: method. I'm using the GM of Xcode 5. I'll upgrade Thursday if I have time and test again.

I've also found that I can't alter the text label background color inside the tableView:cellForRowAtIndexPath: method, but can in the tableView:willDisplayCell:forRowAtIndexPath: method.

To fix the separator lines add the following to characterListTableView setup.
Code:
        [characterListTableView setSeparatorInset: UIEdgeInsetsMake(0, 0, 0, 0)];

This all seems very messy. :mad: Flipping back and forth between SDKs is unusual, but now I know a few more things to watch out for. :D

I didn't understand your question.
 

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
Thanks Guys!

I started to implement an IOS system version check
Code:
//Header
float deviceVersion;


//Imp
UIDevice *deviceData = [UIDevice currentDevice]; // Get device info
if (deviceData)
    deviceVersion = [[deviceData systemVersion]floatValue];
else
    deviceVersion = 1.0;

xStep- Thanks for the code snipit because that is what I was looking for as well to adjust that problem. When I popped that code in it crashed my 6.0 simulator. So I placed it in an if statement

Code:
if (deviceVersion >= 7.0) {
        [characterListTableView setSeparatorInset: UIEdgeInsetsMake(0, 0, 0, 0)];
}
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Do that like this


Code:
BOOL CurrentOSVersionIsGreaterOrEqualTo(NSString* inOSVersion)
{
	NSString *osVersion = [[UIDevice currentDevice] systemVersion];

	return ([osVersion compare:inOSVersion options:NSNumericSearch] >= NSOrderedSame);
}

if (CurrentOSVersionIsGreaterOrEqualTo(@"7.0")) { 
// iOS 7
}

Although for what you're looking at it might be better to check if setSeparatorInset: exists and call it then.
 

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
PhoneyDeveloper - I have to ask. Why is that a better way to check the current version then what I did? In my init method I get the ios version number and if it is 7.0 and assign that to a float as a global variable that all methods can see.

Your version creates a function to test and then returns a BOOL. They both seem to server the same purpose. But with mine it only checks 1 time and stores the value.

Is my version not safe?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
@"7.0.2" is not a float. It's not a good idea to convert a system version to a float. It's a string in a numerical format. The NSString numerical comparison method will compare system versions, as strings, correctly.

Honestly, I have no idea what [@"7.0.2" floatValue] is. Do you?

In my code I set several BOOLs one time when the app launches using the method I showed and then read them throughout the app as the code needs to know the system version. But that's just an optimization.

BOOL isv5OrGreater;
BOOL isv6OrGreater;
BOOL isv7OrGreater;
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
In my code I set several BOOLs one time when the app launches using the method I showed and then read them throughout the app as the code needs to know the system version. But that's just an optimization.

BOOL isv5OrGreater;
BOOL isv6OrGreater;
BOOL isv7OrGreater;

Just curious, PhoneyDeveloper: do you set up these BOOLs in your appDelegate or elsewhere? Are they instance variables? And then how do you read them? I'm always interested to see how others implement a concept such as this? (In other words, willing to share a bit more code?)
 

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
@"7.0.2" is not a float. It's not a good idea to convert a system version to a float. It's a string in a numerical format. The NSString numerical comparison method will compare system versions, as strings, correctly.

Honestly, I have no idea what [@"7.0.2" floatValue] is. Do you?

In my code I set several BOOLs one time when the app launches using the method I showed and then read them throughout the app as the code needs to know the system version. But that's just an optimization.

BOOL isv5OrGreater;
BOOL isv6OrGreater;
BOOL isv7OrGreater;

OK, thanks. I see what you are talking about now.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.