0

I'm creating a simple application with uitableview. I want to create everything in code. I used following code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    FBVCalendarViewController *calendarViewController = [[FBVCalendarViewController alloc] init];

    self.window.rootViewController = calendarViewController;
    [self.window makeKeyAndVisible];
    return YES;
}

...

- (void)loadView
{
    UITableView *calendarItems = [[UITableView alloc] init];
    self.view = calendarItems;
}

it works, but application fills the entire phone screen intersecting with standard phone title bar.

What is the right way to adjust view height?

vbezhenar
  • 11,148
  • 9
  • 49
  • 63

2 Answers2

2

Since UITableView inherits from UIScrollView, you should take care of the changes appeared with IOS 7.

A solution to your problem is:

 if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {

        [self setNeedsStatusBarAppearanceUpdate];
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

(this will keep the table view below the status bar).

Hope that helps. But you should probably have a look at changes introduced with IOS 7.

Benjamin Trent
  • 7,378
  • 3
  • 31
  • 41
anamaria
  • 36
  • 3
1

So I solved my problem with the following code in loadView:

- (void)loadView
{
    UITableView *calendarItems = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];

    UIView *rootView = [[UIView alloc] init];
    [rootView addSubview:calendarItems];
    self.view = rootView;
}

I used empty UIView as a parent for tableView and changed constructor to explicitly specify UITableView frame. I think that better approach would be to use autolayout (currently it just does not work as expected when I rotate device) and position table view to the full screen or implement device rotation callback and update frame there.

vbezhenar
  • 11,148
  • 9
  • 49
  • 63