I'm using a UITableViewController subclass in iOS 7.
Before I added the search bar as the table view's tableHearerView, the UIRefreshControl worked as I expected: I triggered beginRefreshing in viewDidLoad and I could see it spinning every time I entered this screen.
After I added the search bar, I can't see UIRefreshControl spinning when I enter this screen. Everything else seems to work fine, e.g pulling down will show the spinning UIRefreshControl.
Did I use the 2 widgets in right way? How to fix this issue so I can see the spinning like what I saw before adding the search bar?
Thanks a lot in advance!
It looks like if you invoke the beginRefreshing method manually you also need to set the offset of the tableView manually.
Here is the solution in Objective-C:
[self.tableView setContentOffset:CGPointMake(0, -self.refreshControl.frame.size.height) animated:YES];
and here the solution in Swift:
self.tableView.setContentOffset(CGPointMake(0, -self.refreshControl!.frame.size.height), animated:true)
Related
I have a UISearchDisplayController working nicely with a UISearchBar. shouldReloadTableForSearchString correctly returns results as the user types, but when the user hits the Search button on the keyboard and searchBarSearchButtonClicked is triggered, something odd happens after the final search results correctly display and the user hits Cancel on the search bar. Once the user reactivates search, the search opens but the cursor doesn't blink, the search results don't display and the keyboard looks locked on every keypress as shown in the attached image. There should be results for "Test", but nothing is happening and something seems to be held up b/c the last pressed key ("T") isn't going back down to the keyboard.
I'm holding off on including code b/c there are a lot of moving parts, but if any code would help, i can quickly include it. Thanks for your help.
UPDATE: it's not just after the user submits the query - if they've touched the resulting searchDisplayController.searchResultsTableView after inputting a query to scroll down through the results, and then hit Cancel, they'll see the frozen cursor and broken search once they activate the searchBar again (same image applies).
SECOND UPDATE: this only happens when I hide / unhide the navbar while search is active in viewWillLayoutSubviews. Any ideas? Really appreciate any help!
-(void)viewWillLayoutSubviews {
if (self.searchDisplayController.isActive && !profileSelected) {
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
else {
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}
LAST UPDATE: when hide/unhide code is placed into searchDisplayControllerWillBeginSearch and searchDisplayControllerWillHideSearch respectively, the searchBar incorrectly unhides 20px below navbar:
fixed it by adding this code:
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
[self.searchDisplayController.searchBar becomeFirstResponder];
}
UISearchDisplayController is using UITableView to show search results. Whenever you scroll or new cells are loaded, viewWillLayoutSubviews is getting called. This is causing the app to freeze. Try moving you setNavigationBarHidden code in a separate method triggered by some other action.
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 have a UITableview that doesn't take up the whole screen (screenshot). Everything worked fine in iOS 6. But in iOS 7, when the user searches, the search result table takes up the whole view (screenshot).
To fix this, I tried setting the frame manually as described in this answer. The appearance is now correct (screenshot), but now the "<" button in the top left doesn't receive tap events when the search results table is displayed.
It seems the searchResultsTableView is adding a full-screen background view that is intercepting touch events. To prove this, I added this code to didShowSearchResultsTableView:
controller.searchResultsTableView.superview.backgroundColor = [UIColor blueColor];`
This screenshot confirms my hypothesis.
How can I fix this to allow the "<" button to receive tap events?
I want to avoid modifying controller.searchResultsTableView.superview so that my change doesn't break in future versions of iOS.
And what change in iOS 7 caused this behavior to start happening?
I am still searching for a better solution, but currently my solution is in the viewControllers viewDidLayoutSubviews tell your view to move to front. The code would look something like this.
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self.view bringSubviewToFront:self.navigationBar];
}
I wanted to show a Settings view, so I figured I could use the pageCurl modal style. I have a UIViewController that I am presenting from:
Settings *settings = [[[Settings alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
settings.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
settings.modalTransitionStyle = UIModalTransitionStylePartialCurl;
settings.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:settings animated:YES];
When the page curls, to reveal my UITableViewController below, the cells subviews (labels and accessory views) seem to animate into position, which looks horrible:
The strange thing is, is that the animation never happens to the top cell in a section. This does not happen with other modalTransitionStyle's so I am wondering why this could be happening. It is really becoming frustrating because I cannot figure out how to stop this from happening.
Ideas?
If you set the autoResizingMask property of the tableView to UIViewAutoresizingNone, I think this won't happen. This may be a little bug in the page curl animation.
I've noticed that the direction of this weird animation (which also happens to UIButtons), depends on the Alignment chosen in the Control section of the object's Attributes inspector (in Interface Builder). I've been tinkering with all attributes all evening and have found no solution yet. :(
Edit: so, I had three UIButton in my view (and one UIPickerView) that where doing this weird behavior at the same time. I created a property linking to ONE of the UIButtons. Then, in the viewDidLoad of this view's controller I added the following line:
_firstAffectedButton.titleLabel.autoresizingMask = UIViewAutoresizingNone;
And that fixed it for me, for all the buttons and the picker!! :? Weird, right?
Can anyone explain why this is working? I have the feeling I'm doing something stupid to fix this, but I can't see what it is.
Edit 2: Turns out there was a better and cleaner solution to this problem. See this post.
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