Life & Technology

Handful lessons in different areas of technology and life in general.

Tag Archives: UISrollView

Horizontal Menu with UITableView Tap Status Bar not working

HorizMenu_ScreenshotYesterday, I downloaded the ABS-CBN News iOS app to see news and articles and let myself update on what’s going on. The application looks good and it feels natural, very intuitive as they presented their menus as a horizontal tab placed on the header and then the content is being changed on the UITableView. Even the UIView Activity Indicator on the bottom is non-intrusive and very well implemented.

But one thing I noticed, when I scroll news up to the bottom and scroll back on top by clicking the status bar, nothing happen, no matter how I try or select different tab, still it won’t work. And upon investigating, the problem is being caused by two UIScrollViews on the main view which prevents the UITableView from responding to scrollToTop.

 

As per Apple documentation:

/*
 this is for the scroll to top gesture. by default, a single scroll visible scroll view with this flag set will get the call. if there is more than one visible with this
 flag set or the delegate method returns NO, the view isn't scrolled 
 */
@property(nonatomic) BOOL  scrollsToTop;          // default is YES. if set, special gesture will scroll to top of view after consulting delegate

To fix the issue, I made a sample iOS application which uses the excellent opensource MKHorizMenu and use his demo application to add a UITableView and a logic that will check and set the scrollsToTop property to false if the UIScrollView implementation is not UITableView as seen below:

- (void)viewDidLoad
{
    self.items = [NSArray arrayWithObjects:@"Headlines", @"UK", @"International", @"Politics", @"Weather", @"Travel", @"Radio", @"Hollywood", @"Sports", @"Others", nil];    
    [self.horizMenu reloadData];

    [super viewDidLoad];
    self.title = @"Tap Status";
    
    for (UIView* v in [self.view subviews])
    {
        if ([v isKindOfClass:[UIScrollView class]])
        {
            if ([v isKindOfClass:[MKHorizMenu class]]) {
                ((UIScrollView *)v).scrollsToTop = NO;
            }
        }
    }
}

Revised Demo application of MKHorizMenu is available for download here.

Hope this helps.