UITableview not visible the last cell when scroll down - ios

I'm very new to iOS. I have a UITableView that filled with many custom cells, but the bottom cell is is not visible properly when scroll down.my Y value of the UITableView is 44 and Height is 480. Only the half of the last cell is visible when scroll down. How can I fixe this problem.
Thanks in advance.

Use -
tableView.contentInset = UIEdgeInsetsMake(0, 0, 120, 0); //values
passed are - top, left, bottom, right
Pass bottom offset as per your needs.

it is because you set your tableview's frame wrong, if your view has a navigation bar , usually use this code:
CGRect frame = self.view.bounds;
frame.height -= 44;
44 is the height of your navigation bar.

If you have a status bar visible on the top, then it will occupy 20px which will push down your tableView by the same. To avoid this, make the tableView height 460 instead of 480.

For me this is worked.
I have commented out my code
-(void)viewWillLayoutSubviews
{
dispatch_async(dispatch_get_main_queue(), ^{
//This code will run in the main thread:
CGRect frame = tableViewObj.frame;
frame.size.height = tableViewObj.contentSize.height;//commenting this code worked.
tableViewObj.frame = frame;
});
}
That's it. It worked for me. Please make sure you have not changed tableview frame some where while in implementation file.

If you are on iOS7 and using a navigation controller toolbar, make sure to set it to translucent:
self.navigationController.toolbar.translucent = NO;

Related

iOS11 customize navigation bar height

First of all, thank you for coming here and help solving my problem. Thank you!!!
In iOS11 beta6, sizeThatFits: seems to not work on UINavigationBar. I notice that UINavigationBar structure has changed by Reveal my app.
I have tried my best to change custom navigation bar's height. But it seems always to be 44, and it works before iOS11.
- (CGSize)sizeThatFits:(CGSize)size {
CGSize newSize = CGSizeMake(self.frame.size.width, 64);
return newSize;
}
Oddly, I just log its frame in didMoveToSuperview method, its height is 64, but I really see that is 44 in Reveal and app.
I have no idea about this... Help me please.. Thank you.
Update:
I found that about my custom navigation bar LayoutConstraints log in console like this :
"<NSAutoresizingMaskLayoutConstraint:0x604000495ae0 FDCustomNavigationBar:0x7fe2f01399d0.(null) == 42>",
"<NSAutoresizingMaskLayoutConstraint:0x604000495b30 FDCustomNavigationBar:0x7fe2f01399d0.height == 44>"`
bug I even no use auto layout in my navigation bar. What's wrong with it?
Update 8/28 :
I have set my custom navigation bar's subviews frame at navigation bar's -
layoutSubviewsmethod.
- (void)layoutSubviews {
[super layoutSubviews];
self.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), 64);
for (UIView *view in self.subviews) {
if([NSStringFromClass([view class]) containsString:#"Background"]) {
view.frame = self.bounds;
} else if ([NSStringFromClass([view class]) containsString:#"ContentView"]) {
CGRect frame = view.frame;
frame.origin.y = 20;
frame.size.height = self.bounds.size.height - frame.origin.y;
view.frame = frame;
}
}
}
but the navigation bar will cover view controller's view. How can I fix that?
Since iOS 11 UINavigationBar fully supports Auto Layout (this is the reason why you're seeing its constraints). I've opened a radar to Apple because I thought that setting a height constraint to the titleView would have adjusted the navigation bar height accordingly. However this is what Apple replied:
Full support for auto layout does not imply that your view can influence other aspects of the layout of the navigation bar – in particular, the navigation bar enforces its own height and does not allow the title view or other custom views to exceed the height of the navigation bar. We are continuing to work on this issue, and will follow up with you again.
As of today the radar is still open.
Hello I just experienced this same issue.
Now the top layout guide is deprecated on iOS 11. You have to reference the safeAreaLayoutGuide in your constraints.
Here's an example in swift
if #available(iOS 11, *) {
let guide = self.view.safeAreaLayoutGuide.topAnchor
let height = (self.navigationController?.navigationBar.frame.height)! - CGFloat(12)
NSLayoutConstraint.activate([
self.yourTableView.topAnchor.constraint(equalTo: guide, constant: height)
])
}
As you can see your view's top anchor should match the safeAreaLayoutGuide top anchor. In this example I'm using the variable height to create the new constraint. The variable height contains the navigation bar height minus a constant.
You should try by changing the height value.
Hope this helps you.

Last cell Not Showing Properly in Tableview

I use Tableview to show library songs and songs play on did select cell,
when song play mini player popup on bottom.
At that time last cell of table view is not show properly, some of its portion hide behind mini player so please suggest.
Thanks
Try to set contentInset
tableView.contentInset = UIEdgeInsetsMake(0, 0, 110, 0); values are - top, left, bottom, right // change as per your needs
OR
- (void)viewDidLayoutSubviews {
CGFloat navbarHeight = 44; // this is supposed to be 64 but you should dynamically calculate it or better use constraints
CGRect tempFrame = self.view.frame;
self.tableView.frame = CGRectMake(tempFrame.origin.x, tempFrame.origin.y, tempFrame.size.width, tempFrame.size.height - navbarHeight);
}
A quick fix can be to add a footer View to your tableview. make the footer view height the same as your mini player. customise the footer view to your needs or make the footer view background colour to clear so it will not be visible.

Set UITableViewHeaderFooterView margin values (on scrolling)

I build a UITableView with section header that can expand a specific section. I am using a custom view from a .xib file for a UITableViewHeaderView. I want to set margin values of the HeaderView so that it is not full width and stays on top when scrolling down (not full height).
As you can see in the animation the view has full width - is it possible to add a margin to the header that there is some space between the HeaderView and the edge of the screen.
I want to reduce the height of the sticky header if the UITableView is scrolled - so that there is just the text of the button visible on top of the screen. I have implemented the following delegate command from UIScrollView which works fine, but it reduces the margin for the first HeaderView so that it moves behind the navigation bar (see in animation) - how can I avoid that?
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 20;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
You could put a subview with a margin in your headerview.
Setting the height is certainly possible and is done by setting the frame, but you could also make your navigation bar non-translucent, which would save you a ton of coding.
[self.navigationController.navigationBar setTranslucent:NO];
If you want to change the height, your code would look something like:
CGRect frame = header.frame;
frame.size.height = 44;
header.frame = frame;
[self.tableView setTableHeaderView:header];

IOS - Keep UIView on top of UITableView on scroll

I have a UITableView with a UIView on top. I want the UIView to stick to the top as the tableView cells scroll over it.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (self.tableView.contentOffset.y > 0) {
CGRect newframe = self.publicTopView.frame;
newframe.origin.y = -self.tableView.contentOffset.y;
self.publicTopView.frame = newframe;
NSLog(#"After: %f", self.publicTopView.frame.origin.y);
}
}
You need to set your table view header view to the view you want on top.
Add this code to you viewDidLoad
self.tableView.tableHeaderView = self.publicTopView
I'm not certain what you're trying to accomplish, but I have a guess at what is wrong. As you scroll your contentOffset will continue to change and let's say your tableView has a content size height of 1500, then your contentOffset will eventually be larger than the height of your view controllers view. Now see that you are putting that contentOffset into the origin.y of your publicTopView. So your publicTopView could possibly be moving too much, even offscreen depending on how large your tableview's content size is.

iOS7 UIRefreshControl changes contentInset

I have a UINavigationController in my app. The UINavigationBar is set to opaque and all the scroll views do not overlap underneath the bar.
In one view I have a UITableView. The frame of the UITableView is (0 0; 320 504) on my iPhone 5. i.e. the height is 568 - 64 (the height of the nav bar and status bar).
The contentInset of the UITableView is (0, 0, 0, 0). When the table view first loads the contentOffset is (0, 0).
This is fine. Works brilliantly.
I added a UIRefreshControl to the table view. This works a couple of times but then after a few times of doing pull to refresh then the content at the top gets "stuck" under the nav bar.
When this happens I inspect the contentInset and it is now (-60, 0, 0, 0).
Is there any way to stop the UIRefreshControl from changing the contentInset?
This is probably the reason why UIRefreshControl is currently only supported on UITableViewController, rather than by addition to any scrollview (which you can get away with, in many cases).
The refresh control does its magic by tinkering with the content insets of the scrollview - particularly when it ends refreshing. Unfortunately the view controller is also tinkering with the content insets of the scroll view to fit it under the translucent nav and status bars. Fun ensues. Is this also an issue on iOS 6 (or, "good old iOS6" as I called it when dealing with the same issue).
The quickest solution is probably to add your table view as a child UITableViewController instead of a simple subview. I think that UITableViewController manages the insets for you at the end of the refresh. If that doesn't work, I've got workarounds for this but it will have to wait until I get back in the office.
I will add this answer here in case any one has problems with UIRefreshControl by changing the control properties (attributed title, tint, etc...):
Don't mess with the UIRefreshControl on -viewDidLoad:, use -viewDidAppear: instead.
Reset your table view contentInset.
-(void)pullToRefresh
{
[self.tableView reloadData];
[self.refreshControl endRefreshing];
[self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
You need override setContentInset: in you UICollectionView
- (void)setContentInset:(UIEdgeInsets)contentInset {
if (self.tracking) {
CGFloat difference = contentInset.top - self.contentInset.top;
CGPoint translation = [self.panGestureRecognizer translationInView:self];
translation.y -= difference * 3.0 / 2.0;
[self.panGestureRecognizer setTranslation:translation inView:self];
}
[super setContentInset:contentInset];
}

Resources