I am currently using a UIScrollView to store 2 tables side by side, similar to how Pinterest does for its Activity page. However, when I tap on the 2nd table and access a new UIViewController, going back would reset the contentOffset, hence, I'm back on the 1st table which is wrong.
Am I able to lock the contentOffset or is there other ways to do this?
Thanks in advance.
Try this in the UIViewController that contains the UIScrollView:
self.automaticallyAdjustsScrollViewInsets = NO;
Related
Problem
I'm trying too make a custom search text field, added to a UITableViewController, always stick to the top of the page.
Like this:
Everything works fine, but when I tap the search text field to becomeFirstResponder the tableView strangely scrolls down.
I have discovered that this only happens when I manually setts the contentInset for the UITableView. (So that the tableview section headers don't hides behind the search view)
How I have built it
Layers:
TableView
UIView (as UITableView.tableViewHeaderView)
UIView (to update the frame when the user scrolling the tableView)
UITextField (for search input)
Code for fixing the search view frame when user scrolls:
var rect = frame
rect.origin.y = scrollView.contentOffset.y + 64
frame = rect
I may be doing everything stupid, but I would like to have the view stick to the top, because the user will use search more than other apps. Any ideas?
My app requires iOS 8 so I have not been available to test this on iOS 7. I can make a screen recording if that helps.
UPDATE
I've created an example project with the same objects I'm using in my main project.
https://www.dropbox.com/s/qdlx0milebbuf3p/Search%20bug%20Example.zip?dl=0
It's a UIKit bug. To fix this I've created a subclass for UITableView to NEVER change the content offset when isScrollEnabled is NO.
.h
#interface CUISearchTableView : UITableView
#end
.m
#import "CUISearchTableView.h"
#implementation CUISearchTableView
- (void)setContentOffset:(CGPoint)contentOffset {
if (self.isScrollEnabled) {
[super setContentOffset:contentOffset];
}
}
#end
I'm not sure you need to do all that. If you'd just use a UIViewController and add a UITableView to that, then you could place the UISearchView anywhere ( i.e., the top of the view ). You just need to make sure that the UISearchView is the top-most view ( bring subview to front ).
I get that you're using a UITableViewController, but if you want to use your own search view instead of the TableViewController+Search then this is your best bet. The only thing that would be necessary is adding the top content offset ( which you're already doing ). you could then just delete the CUISearchTableView.
Does this make sense or am I missing something?
Sorry if my question seems stupid but I've been trying everything to get it to work for several days now and nothing comes to my mind anymore.
I'm trying to use SVPullToRefresh on a UIScrollView which is, in my storyboard, fixed to the main view of my View Controller (space constraints to superview 0,0,0,0).
Code is pretty straightforward :
__weak ALExploreViewController *weakSelf = self;
[self.globalScrollView addPullToRefreshWithActionHandler:^{
[weakSelf refreshData];
}];
[self.globalScrollView triggerPullToRefresh];
The thing is, when I launch the app, the pull to refresh appears as I triggered it in code. Then I make it disappear when my data are updated (self.globalScrollView.showsPullToRefresh = NO;). And then when I scroll up to refresh, the "pull to refresh" view won't show. If I deactivate bouncing, the view won't event scroll upper than y=0, and if I activate it, it bounces but no sign of the P2R view.
Any ideas ? Please ?
You should not use self.globalScrollView.showsPullToRefresh = NO;, this is used to disable the refreshView.
When your data is updated, you can call
- (void)stopAnimating;
Try it!
I want to get information about how UITableView would be scrolled without actually schange scrollView.contentOffset. I cant use scrollEnabled property becouse its stop fireing scrollViewDidScroll event on table and I need it. Is there any way to do it?
The question is a little bit hard to understand but in any case scrolling on a UITableView will modify contentOffset. That's how the superclass, UIScrollView, works.
As for scrollViewDidScroll, it is only called automatically when the user scrolls the view, but you can override setContentOffset to trigger it manually when needed. Just to avoid a loop set a BOOL dragging = YES flag on scrollViewWillBeginDragging: and clear it on scrollViewDidEndDragging:willDecelerate:.
I am trying to add content 'above' the top of my UICollectionView and have the code call a method if the user scrolls up far enough.
It would be similar to 'pull to refresh' but I want it to present another view rather than refresh the data.
This behaviour is found in the 'Clear' app when you navigate 'up' and 'down' between the different lists.
Thanks in advance for your help.
Edit:
I found out how to add the content above using this:
UIView *topview = [[UIView alloc] initWithFrame:CGRectMake(0,-480,320,480)];
[self.tableView addSubview:topview];
Now I need to figure out how to respond to a user scrolling beyond the top of the collection view.
I think that you'll find that UICollectionView bases a lot off of UITableView. Have you tried leveraging methods similar to what the old self-made pull-to-refresh classes did? Something along the lines of:
if (isDragging && scrollView.contentOffset.y < 0)
I'm trying to disable scrolling in a UITableView when editing a UITextField embedded in a UITableViewCell.
This is just to prevent the cell from being scrolled out of sight when edited (and also to avoid some related cell "Recycling" problems).
While googling around I've seen that somebody suggested the obvious:
tableView.scrollEnabled = NO:
or even
tableView.userInteractionEnabled = NO;
This does not work though (at least for me... iPhone SDK 3.0, tried on simulator)
I set these properties to NO, I even check by logging that the properties are set to NO, but the UITableView keeps on responding normally to touch events.
And it also happily scrolls.
I wouldn't be that worried if somebody on the net were not claiming that this actually works.
Am I missing something?
Or is the only alternative subclassing UITableView to make a functionality available in its superclass (UIScrollView) work again?
Did you try using
self.tableView.scrollEnabled = NO;?
I've often tried that code from the web didn't work, simply because of a lack of the prefix self. I just tried this out without a problem.
I don't know if this work when turning it on and off dynamically. It does at least work for permanent settings when initializing the object...
If you're using UITableViewController, you also have a tableView property, with no casting needed. This works for me:
self.tableView.scrollEnabled = NO;
Let me know if that works for you.
Did you try on storyboard unselect scrolling enabled?
I tried:
[(UIScrollView*)[self view] setScrollingEnabled:NO];
and it worked ([self view] is my view of the current view controller, i.e., a UITableView).
The thing is, I get a warning:
'UIScrollView' may not respond to '-setScrollingEnabled:'
In all honesty, the property is "scrollEnabled", but it works nonetheless with the aforementioned code!
So, the "right" way to do things, should be:
[(UIScrollView*)[self view] setScrollEnabled:NO];
Why it also works the other way, is confusing me...
None of these answers worked in my case. Table view kept scrolling ever though every scrollView was disabled.
Finally, I've found solution in here, claiming that UITableViewController does this "for me" whenever keyboard hides the UITextView being edit.
Solution is to inherit from UIViewController instead of UITableViewController and implement the required table functionality myself.
if you want to scroll only if its content is not visible then set:
yourTableview.alwaysBounceVertical = NO;
Here if your content is visible then your tableview will not scroll