AXStretchableHeaderTabViewController icon indicating copy to clipboard operation
AXStretchableHeaderTabViewController copied to clipboard

Select the second sub view controller

Open johannwilfling opened this issue 10 years ago • 1 comments

What's the recommended way to make the second sub view controller selected after the AXStretchableHeaderTabViewController has loaded?

johannwilfling avatar Sep 14 '14 16:09 johannwilfling

I added some additional methods to "AXStretchableHeaderTabViewController.m" to add this feature.

-(void)setCurrentViewControllerToIndex:(int)index
{
    if(_viewControllers.count > index)
    {
        [_tabBar setSelectedItem:_tabBar.items[index]];
        [self didSelectTabBarItemAtIndex:index];

        [self layoutSubViewControllerToSelectedViewController:self.selectedViewController];
    }
}

-(void)setCurrentViewControllerToTabName:(NSString *)tabName
{
    //search through each tab bar button to find out which one matches the requested page
    [_tabBar.items enumerateObjectsUsingBlock:^(UIBarButtonItem *barButton, NSUInteger idx, BOOL *stop)
    {
        //if the button matches our text
        if([barButton.title isEqualToString:tabName])
        {
            //get the index of this button and set the view controller based on this index
            int indexOfButton = (int)[_tabBar.items indexOfObject:barButton];
            [self setCurrentViewControllerToIndex:indexOfButton];

            //return out of the enumeration, we only expect to find one match
            return;
        }
    }];
}

CZyMfnIPC avatar Feb 04 '15 21:02 CZyMfnIPC