LeveyTabBar点击Tabbar刷新页面

原码地址:https://github.com/levey/LeveyTabBarController

修改码地址:  http://pan.baidu.com/share/link?shareid=314341&uk=1277579135

在项目中使用LeveryTabBar,需要刷新指定页的数据。在网上查看后,得到Tabbar的刷新方法,即调用

UITabBarController* tab = [[[UITabBarController alloc] init] autorelease];
    tab.viewControllers = array;
    tab.delegate = self; //
    // TabBarController Delegate methods   
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
    {
            // Reload selected VC's view
        [viewController.view setNeedsDisplay];
    }

在LeveryTabBar中,是通过protocol的方法进行实现的。

@protocol LeveyTabBarControllerDelegate <NSObject>

@optional

- (BOOL)tabBarController:(LeveyTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;

- (void)tabBarController:(LeveyTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;

@end

于是我进行了LeveyTabBarControllerDelegate协议的添加。自己去调用- (void)tabBarController:(LeveyTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;函数,然后进行指定页面的刷新。

#pragma mark - Private methods

- (void)displayViewAtIndex:(NSUInteger)index

{

    // Before change index, ask the delegate should change the index.

    if ([_delegaterespondsToSelector:@selector(tabBarController:shouldSelectViewController:)]) 

    {

        if (![_delegatetabBarController:selfshouldSelectViewController:[self.viewControllersobjectAtIndex:index]])

        {

            return;

        }

    }

    // If target index if equal to current index, do nothing.

    if (_selectedIndex == index && [[_transitionViewsubviews] count] != 0

    {

        return;

    }

    NSLog(@"Display View.");

    _selectedIndex = index;

    

UIViewController *selectedVC = [self.viewControllersobjectAtIndex:index];

selectedVC.view.frame =_transitionView.frame;

if ([selectedVC.viewisDescendantOfView:_transitionView]) 

{

[_transitionViewbringSubviewToFront:selectedVC.view];

}

else

{

[_transitionViewaddSubview:selectedVC.view];

}

    

    // Notify the delegate, the viewcontroller has been changed.

    if ([_delegaterespondsToSelector:@selector(tabBarController:didSelectViewController::)]) 

    {

        [_delegatetabBarController:selfdidSelectViewController:selectedVC];

    }

        if (index ==0) {

        [selftabBarController:selfdidSelectViewController:selectedVC];

    }

}

//重新加载视图

- (void)tabBarController:(LeveyTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{

    [viewController viewWillAppear:YES];

}

次方法不知具体好坏,请高手多多指教。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值