Anand Gautam
Anand Gautam

Reputation: 2579

How to remove extra space from the top of the Table View in iPhone X using Objective C iOS

I have already developed an app in Objective C which is working fine in all the iPhone mobiles. But when I am running this app in iPhone X Simulator then I dont know how I am getting some extra space (about 20-22 pixels) in the top of the UITableView. I tried all this solutions, but none of the below helped me :

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];

self.edgesForExtendedLayout = UIRectEdgeNone;

[tblProducts setSectionHeaderHeight:0];

self.automaticallyAdjustsScrollViewInsets = NO;

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

I know this can be possible by setting my table view contentInset like :

tblProducts.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);

Is there any other solution to resolve this issue for iPhone X?

I checked my table view frame in ViewDidLoad, It's (0, 64, WIDTH, HEIGHT), Is there any problem with Status bar?

Please suggest me. Thank you in Advance!

Upvotes: 3

Views: 1443

Answers (3)

ankita kotadiya
ankita kotadiya

Reputation: 1

You can set tableview style grouped to plain it will remove extra space or you can set one property to your Viewcontroller is

self.extendedLayoutIncludesOpaqueBars = true

Upvotes: 0

Devang Tandel
Devang Tandel

Reputation: 3008

If Anyone is looking for answer with storyboard then select your UITableView in storyboard and just change the content inset to never, like shown in below link

enter image description here

Upvotes: 6

Glenn Posadas
Glenn Posadas

Reputation: 13300

You can try setting contentInsetAdjustmentBehavior property to Never.

In Swift, I have this in UICollectionView:

if #available(iOS 11.0, *) {
    collectionView.contentInsetAdjustmentBehavior = .never
}

In Objective-C, the same applies to UITableView, set it like so:

if (@available(iOS 11.0, *)) {
    [_tableView setContentInsetAdjustmentBehavior: UIScrollViewContentInsetAdjustmentNever];
}

Upvotes: 8

Related Questions