ideawu
ideawu

Reputation: 2337

UITableView bottom area keeps out of screen if navigationBar.translucent is NO;

I use UITableView instance as the subview of my ViewController's view, the table's content is higher than the screen so it is scrollable. Here is the code in AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)opts {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UINavigationController *nav = [[UINavigationController alloc] init];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];

    UIViewController *controller = [[ViewController alloc] init];
    [nav pushViewController:controller animated:YES];

    // set to No cause the problem
    nav.navigationBar.translucent = NO;

    return YES;
}

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;

    [self.view addSubview:_tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    cell.textLabel.text = [NSString stringWithFormat:@"test %u", indexPath.row];
    return cell;
}

@end

Now the problem is

Seems like the auto hidden area is of the height of navigationBar, any one who knows how to fix it? I want it work the same no matter translucent = YES or translucent = NO.

Upvotes: 0

Views: 99

Answers (2)

Anon
Anon

Reputation: 623

Try this & let me know if it works:

self.tableView.contentInset = UIEdgeInsetsMake(44,0,0,0);

Upvotes: 1

ideawu
ideawu

Reputation: 2337

I figure out the solution, I set the tableView as the mainview of the controller, not a subview of the controller's mainview

[self setView:_tableView];

instead of

[self.view addSubview:_tableView];

Upvotes: 0

Related Questions