UIRefreshControl in a UIScrollView is not triggered when Large title is used - ios

When i use large titles for the Navigation bar, the added UIRefresh control for the UIScrollView is not triggered when pulled down
{
self.scrollView.refreshControl = [[UIRefreshControl alloc] init];
[self.scrollView bringSubviewToFront:self.scrollView.refreshControl];
// add target
}
When i use normal small titles, it starts working by triggering the event
How to make it work with large titles?

I had the same problem a while ago and for me I could make it work by calling scrollView.refreshControl.didMoveToSuperview() in viewDidAppear.

Related

UICollectionView UIRefreshControl Doesn't Animate After Visiting a Different View

I have a UIRefreshControl connected to a UICollection that is defined this way for pull to refresh:
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:#selector(startRefresh:)
self.collectionView.alwaysBounceVertical = YES;
[self.collectionView addSubview:self.refreshControl];
This works fine. However, whenever I move to a new view by either pushing a new view controller or displaying the sliding sidebar menu, and return to this view, the refresh control starts displaying the image for a control pulled all the way (i.e. it doesn't animate and shows the full circle). However, if I pull down fully and release, the refresh control returns to normal functionality. The control works fine, it just looks funky the first time you pull after navigating elsewhere.
I would love any feedback on what might be going wrong. Thanks!
This is what the image looks like when not working (note I am linking to an online image, this is not from my app so this doesn't show that the collectionview is being pulled down):
Posted solution below worked, but I had to do some extra work to figure out when my top view controller received focus from the sidebar menu that I was using (ECSlidingViewController): Is there a way for the Top View Controller in ECSlidingViewController to know when the sidebar menu has been dismissed?
After completed loading You have to stop the refreshing
[tableView.refreshControl endRefreshing]
Hope its useful for you..:)
I had a slightly different issue but the symptoms were similar. This is what worked for me:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_refreshControl.hidden = YES;
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
if (_refreshControl.isRefreshing) {
[self.collectionView sendSubviewToBack:_refreshControl];
}
}

Why does UIWebView Not Scroll?

I've looked at numerous questions similar to this but try as I might, I cannot get a UIWebView to scroll or interact in any way. Here is the code:
- (void)loadView {
[super loadView];
...
[self.displayView loadHTMLString:entry->infoHtml baseURL:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.displayView.userInteractionEnabled = YES;
self.displayView.scrollView.showsVerticalScrollIndicator = YES;
self.displayView.scrollView.scrollEnabled = YES;
[self.displayView.scrollView flashScrollIndicators];
}
The view appears, displays all the correct content, and shows the vertical scroll-bar for a second, correctly indicating the portion of the content currently displayed.
But I can't scroll it. Touching the content and moving my finger around does nothing at all. Interacting with a non-overlapping UITableView under the same parent works fine; touching entries there updates the contents of the UIWebView as it has been programmed to do.
The UIWebView was created in the Storyboard with these options:
Scales Page To Fit: unchecked (when checked, can't pinch-to-zoom, either)
Pagination: unpaginated
Mode: Aspect Fit (tried several; all un-scrollable)
UserInteractionEnabled: checked (parent views also have this checked)
The view is fully visible. I've tried making it significantly smaller than its parent and the displayed content always stops at the correct place. There is no delegate or gesture recognizers for this view.
The containing view has a UITableView and a UILabel, neither of which overlap the area of the UIWebView. I've tried changing the order of the views in the Scene on the storyboard but that also makes no difference.
I've tried removing the view from UIBuilder and creating it programmatically like so:
self.displayView = [[UIWebView alloc] initWithFrame:CGRectMake(400, 220, 400, 300)];
[self.view addSubview:self.displayView];
Same results. I tried removing all other elements from the Scene except for this single programmatically created UIWebView. Still the same results.
Elsewhere in my code, I've put a UIWebView as the #"accessoryView" of a UIAlertView and there I can scroll the content as expected.
Is there something else that needs to be done to be able to scroll a UIWebView sub-view?
2014-04-20: In fact, if I add the following lines to the bottom of my -loadView method, I get a dialog with the same HTML content as the window behind it, but I am able to scroll the dialog version. The only difference I can think of is that the dialog is modal (forced focus) while my own window with both a UITableView and UIWebView still allows interaction with the views visible behind it.
UIWebView* contents = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
[contents loadHTMLString:entry->infoHtml baseURL:nil];
[alertView setValue:contents forKey:#"accessoryView"];
[alertView show];
On the other hand, if I replace the last two lines of that with [self.view addSubview:contents]; then I get the same second HTML view in the upper-left corner of the screen but that will not scroll.
I've worked it out. First, I tried adding this to -viewDidLoad in my MainController class:
UIWebView* contents = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
[contents loadHTMLString:#"<html><head><title>FOO</title></head><body><p>A</p><p>B</p><p>C</p><p>D</p><p>E</p><p>F</p><p>G</p><p>H</p><p>I</p><p>J</p><p>K</p><p>L</p><p>M</p><p>N</p><p>O</p><p>P</p><p>Q</p><p>R</p><p>S</p><p>T</p><p>U</p><p>V</p><p>W</p><p>X</p><p>Y</p><p>Z</p></body></html>" baseURL:nil];
contents.backgroundColor = [UIColor redColor];
[self.view addSubview:contents];
It displays but isn't scrollable. I have a StartupController that deals with initializing the app and runs first so I added the same code there. This was scrollable! Ah-Ha!
It occurred to me that the top-level Google Map (GMSMapView) that covers the MainView might be swallowing the scroll events but passing click events. Within the scene, instead of just a single map-view, I created a top-level plain/simple/empty UIView and made the GMSMapView a full-sized child of that. Now when I add my views to that new top-level (simple) view, they are siblings rather than children of the map and get all events correctly.
As a result, my UIWebView is now scrollable. Thanks for everybody's comments and suggestions! It's been several months of on-and-off trying different things to finally figure that one out.
Please check that the web view is contained fully within the bounds of its parent view (and so on up the view hierarchy). An easy way to do this is to set some background colors. Possibly you have some constraints that aren't behaving as you expect.
Similarly, that all parent views are user-interaction-enabled.
Edit: I understand that the web view is fully visible. But that doesn't mean it is contained within the bounds of its superview. If the superview has clipsToBounds=NO (default, I believe) then any subview outside its bounds will be visible but will not receive touches.

Main UITableVew is visible in searchResultsTableView status bar

I have two UITableViews in my app (one for regular usage and another for searching). When I use regular one the status bar is opaque but when I enter searchResultsTableView I can see some items from regular UITableView.
As you can see the UISearchBar is opaque so there is nothing behind it but status bar is still transculent.
I've already added [self.tableView setHidden:YES]; in searchDisplayController: willShowSearchResultsTableView: but it's a very primitive solution and does not work when my regular UITableView is displayed at the beginning of search.
My question is how to make status bar opaque? Just to avoid this annoying thing.
I've found two solutions to this issue. Both works for me but the second one is simpler and you don't have to do anything in code. I hope you find it useful!
First solution:
You can create a custom UIView in code and add as a subview. If your application has one color of UINavigationBar or any other component and it won't change through the lifecycle you can always implement this in application:didFinishLaunchingWithOption:. Otherwise, you can always add this code in proper moment but you have to remember to add this subview to proper super view. Here is the code sample:
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0.79 green:0.79 blue:0.81 alpha:1];
[self.navigationController.view addSubview:addStatusBar];
Second solution:
There is one tiny checkbox in Xcode called Clip Subviews and it's super useful in that case. You can find the view which is visible under Status Bar (In my case it's UITableView) and clip it to subviews. I don't know how but in my case UISearchBar started affecting status bar so now it's opaque qith a color of UISearchBar.

Disabling UIGestureRecognizers in underlying ViewController

In a View Controller I'm building a grid of icons.
Each icon opens the same pop-up view , but filled in with different information.
I'm creating the grid in this way:
for (int i=0; i<NUM_BADGES; i++) {
BadgeThumbView *thumb = [[BadgeThumbView alloc] initWithFrame:CGRectMake(posX, posY, 70, 100)
andWithLabel:[NSString stringWithFormat:#"BADGE NAME N. %d", i]];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(onBadgeTapped:)];
[thumb addGestureRecognizer:gestureRecognizer];
[thumb setTag:i];
[more code here....]
}
And in onBadgeTapped method I'm creating the pop up.
Now my problem is that everything works fine, but I just realized that when the pop up is opened, while interacting with its buttons I'm still triggering the gesture recognizer in the underlying view controller.
Is there a way to disable all GestureRecognizers in underlying view? Is my strategy wrong? And: is there a way to use a single UIGestureRecognizer for all my icons, in order to disable/enable in a easier way?
Thanks a lot
You can remove the recognizer from view or set userInteractionEnabled to temporarily disable it. Depending on how your popup is implemented, you may be able to disable them all at once.
One solution would to be adding thumbs as a subview of a container UIView, and adding that container to your parent view. You could then enable/disable all by setting userInteractionEnabled on the container view.
I think you should do some thing like disabling the userInteraction for all thumb views when the popup is appearing and re-enabling when disappearing like this
[[yourSuperView subviews]makeObjectsPerformSelector:#selector(setUserInteractionEnabled:) withObject:[NSNumber numberWithBool:FALSE]];
Else add all thumbViews to one subview( say 'b') then add view 'b' to superview(say 'a') as subView and turn off the user interaction to view b when popup appeared and turn on when popup disappears

Custom NavigationBar

I have a Navigation Controller as the root of my app and I am using the appearance proxy to customise the look on iOS 5, but for iOS 4 I was hoping to use a category to override drawRect:, this was fine, except that all the Navigation bars were affected as you would expect from a category.
I don't want to tamper with the "system" popups, such as the Mail composer, or the SMS composer, I want their bars to stay blue and system-like.
I Tried to create my own UINavigationController with it's xib and change the class of the NavigationBar to my custom sub lass of UINavigationBar. But the results are not taking affect at all on screen.
I am aware of the following post but couldn't get any solutions to run as expected.
How to subclass UINavigationBar for a UINavigationController programmatically?
My first attempt which does work but uses an undocumented setNavigationBar: method:
_myNavigationController = [[UINavigationController alloc] initWithRootViewController:someVC];
if([[BT_NavigationController class] respondsToSelector:#selector(appearance)]){
// some iOS 5 magic in here !
[_myNavigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"topbar.png"];
}else{
// Probably looking at app store refusal
CustomBar * bar = [[CustomBar alloc] init];
// [_myNavigationController setNavigationBar: bar];
[bar release];
}
[parentView presentModalViewController:_myNavigationController animated:YES];
To avoid that I created a UINavigationController, which I also had a xib for, reassigning the class of the navigation bar to my custom class, but placing breakpoints in drawRect: method, I can see that this isn't being called.
Why would that be, it seems that my code is not loading the nib, and therefore not realising the nab bar should be my custom class and not the UINavigationBar.
Any tips would be helpful, thanks.
If your modification is just about adding an image, you can simply insert it from the view controllers you want to customize:
UIImageView *bgImageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"topbar.png"]] autorelease];
[self.navigationController.navigationBar addSubview:bgImageView];
You have to tweak a little based on what other elements you have in your UINavigationBar for your UIImageView to be at the lowest index of the subviews but still above the background. Worked for us.
Good luck.

Resources