原码地址: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];
}
次方法不知具体好坏,请高手多多指教。