开发者

UITableview changing height when shown from different UINavigationControllers ('More')

开发者 https://www.devze.com 2023-01-29 21:55 出处:网络
I\'m having an issue with UITableViewController\'s tableView changing its frame position when presented from a UITabBarController, within a UINavigationController. The frame is fine when displayed fro

I'm having an issue with UITableViewController's tableView changing its frame position when presented from a UITabBarController, within a UINavigationController. The frame is fine when displayed from a regular tab. However, if I move and show the UITableViewController from the 'More' Section, the tableview moves down the same height as the navigation bar (which I don't want it to). When I tested the runtime frame coordinates between proper and nonproper positions, it shows as the same (0.0, 0.0, 320.0, 411.0). This issue only happens AFTER I've shown the tableView in one Nav Controller and then it's moved and shown in another, like开发者_C百科 the 'More' VC to the tab, or tab to the 'More' VC

What's going on here and how can I fix this?

The last image is how it looks like when the app launch, as it should be, with he table view right below the nav bar. In the first two however, you can see that the tableview has been moved down.

Thanks in advance!

UITableview changing height when shown from different UINavigationControllers ('More')

UITableview changing height when shown from different UINavigationControllers ('More')

UITableview changing height when shown from different UINavigationControllers ('More')


I was able to solve the issue. It turns out that when you move a UITableView controller within a UINavigationController to the moreNavigationController, 44 pixels are added to the 'top' variables of contentInset and scrollIndicatorInsets. I'm not sure why this is happening or why those 44 pixels aren't being removed when the tableView leaves the 'moreNavigationController', but here's the answer. I'm calling these two lines from within viewWillAppear.

self.tableView.contentInset = UIEdgeInsetsMake(44.0, 0.0, 0.0, 0.0);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(44.0, 0.0, 0.0, 0.0);


The UITableViewController has this behaviour that it always try to best fit the screen size. UITableViewController is perfect for fullscreen tableview but otherwize I recommend not using the UITableViewController but instead implement a tableViewControler yourself by implementing both the datasource and delegate. Some did set resizeSubViews to NO and solve their problem but I really advice recreate the controller yourself which is not that much work.


Reset autosizing property of table view nib file.

You can find it inside : Tool>Attribute Inspector


First take a UITableView in the view using XIB. Then add navigation bar and resize the tableview. You will get what do you actually want.

UITableview changing height when shown from different UINavigationControllers ('More')

If you still find any problem then please let me know.


If you can display your code, or take a screenshot of your setup, it would be a lot easier. From my experience, creating UITableViewController instances and hooking them up in Interface Builder will expand to fill the screen.

How are you connecting it to the "More" tab? If it's in two tabs, and you're doing ANYTHING dynamic, check your UITableViewController class viewDidLoad method. You shouldn't have to add / delete / re-add the table unless they're separate instances.

Some places to check:

  1. NSLog your tableHeaderView height and position
  2. NSLog your tableFooterView height and position
  3. Create a backgroundView and assign it to the tableView's backgroundView property to see what it's true dimensions are and where it's being displayed
  4. Check where the UITableViewController's view starting position is.

Wish I could help more. Would like to see your setup / code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号