Table view contents overlaps status bar


#1

Unfortunately the book fails to provide any details on new iOS 7 rules regarding insets and positioning of view contents. As a result the apps look scrambled with contents overlapping status bar etc. Chapter 8 does not mention this and just shows screenshots that do not match the code provided.

Chapter 9 continues this trend and header view button is also misplaced. Looks like the book overlooks some significant iOS7 changes, which is quite a disappointment.


#2

So has anyone figured out how to programmatically set a top constraint so that the status bar doesn’t overlap the UItableview ?

I tried adding this bit of code to both the init: and viewDidLoad: methods, but it didn’t do didley. Any other ideas out there ?

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect tableRect = CGRectMake(screenRect.origin.x, screenRect.origin.y+200, screenRect.size.width, screenRect.size.height);
[self.tableView setFrame:tableRect];

I did some googling and oh my god the answers were all over the place, lots of talk about autolayout etc etc (which is a future chapter I have not yet gotten to), but they seem to address solutions dealing with the Interface Builder rather than programmatic solutions.

PS - I am adding 200 just to see a drastic change if it works, from what I read you should be adding an extra 20pt at the top (at least for iphone, other devices might be different I think).


#3

yeah, with storyboard, this problem will never happen.


#4

I added this inside of BNRItemsViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView setContentInset:UIEdgeInsetsMake(50,0,0,0)]; /// The remainder of the code stays the same // }

I think you could put it in viewDidLoad, but it made more sense to make the inset happen when the method is called to draw the table. After I figured it out, I felt like this :smiley:


#5

[quote=“dcdude1776”]I added this inside of BNRItemsViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView setContentInset:UIEdgeInsetsMake(50,0,0,0)]; /// The remainder of the code stays the same // }

I think you could put it in viewDidLoad, but it made more sense to make the inset happen when the method is called to draw the table. After I figured it out, I felt like this :smiley:[/quote]

This is mostly correct. I address this issue in this post: viewtopic.php?f=490&t=8424.

As I mention in that post, you’ll probably want to adjust the contentInset as well as the scrollIndicatorInsets.


#6

Hi all,

I think the cleanest way to accomplish this is to set the itemsViewController in a UINavigationController. This gives it a proper “header” and resolves the issue you’re having with regard to the status bar. Here’s my code from the app delegate’s application:didFinishLaunchingWithOptions: method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    JJItemsViewController *itemsViewController = [[JJItemsViewController alloc] init];
    UINavigationController *navigationVC = [[UINavigationController alloc] initWithRootViewController:itemsViewController];
    itemsViewController.title = @"Homepwner";
    
    self.window.rootViewController = navigationVC;
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

Try that and let me know if it fixes your problem!


#7

[quote=“catonkeyboardjsjsjsj”]Hi all,

I think the cleanest way to accomplish this is to set the itemsViewController in a UINavigationController. This gives it a proper “header” and resolves the issue you’re having with regard to the status bar. Here’s my code from the app delegate’s application:didFinishLaunchingWithOptions: method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    JJItemsViewController *itemsViewController = [[JJItemsViewController alloc] init];
    UINavigationController *navigationVC = [[UINavigationController alloc] initWithRootViewController:itemsViewController];
    itemsViewController.title = @"Homepwner";
    
    self.window.rootViewController = navigationVC;
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

Try that and let me know if it fixes your problem![/quote]

It worked flawlessly, thank you!


#8

[quote=“davegomez”][quote=“catonkeyboardjsjsjsj”]Hi all,

I think the cleanest way to accomplish this is to set the itemsViewController in a UINavigationController. This gives it a proper “header” and resolves the issue you’re having with regard to the status bar. Here’s my code from the app delegate’s application:didFinishLaunchingWithOptions: method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    JJItemsViewController *itemsViewController = [[JJItemsViewController alloc] init];
    UINavigationController *navigationVC = [[UINavigationController alloc] initWithRootViewController:itemsViewController];
    itemsViewController.title = @"Homepwner";
    
    self.window.rootViewController = navigationVC;
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

Try that and let me know if it fixes your problem![/quote]

It worked flawlessly, thank you!

[/quote]

Happy to help. :slight_smile:


#9

You can also use the following code if you don’t want to add a navigation controller. Probably best put in the viewDidLoad method.

self.edgesForExtendedLayout=UIRectEdgeNone; self.extendedLayoutIncludesOpaqueBars=NO; self.automaticallyAdjustsScrollViewInsets=NO;

Keep in mind that if you are programming for both iOS7 as well as versions below you will have bugs and then you want to use the following code.

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) { self.edgesForExtendedLayout=UIRectEdgeNone; self.extendedLayoutIncludesOpaqueBars=NO; self.automaticallyAdjustsScrollViewInsets=NO; }