我做了一個自定義UITabBar工作得很好,但我介紹了導航的變化,現在我有一些嚴重的問題。以下是我有:自定義TabBar失去TabBarItem圖像
常規設置
TabBarController
NavbarController1 - TabBarItem1
Links to: PeopleView
NavbarController2 - TabBarItem2
Links to: ContentView
NavbarController3 - TabBarItem3
Links to: ContentView //Same VC as TabBaritem 2.
應用代表 - 在我的didFinishLaunchingWithOptions方法我稱之爲customizeTabBar方法如下
-(void) customizeTabBar
{
UITabBarController *tabVC = (UITabBarController *) self.window.rootViewController;
//Load Navigation Bar images
NSArray *unSelectedImages = [[NSArray alloc] initWithObjects:@"image1.jpg", @"image2.jpg", @"image3.jpg", @"image4.jpg", @"image5.jpg", nil];
NSArray *selectedImages = [[NSArray alloc] initWithObjects:@"image1_on.jpg", @"image2_on.jpg", @"image3_on.jpg", @"image4_on.jpg", @"image5_on.jpg", nil];
NSArray *items = tabVC.tabBar.items;
for (int idx = 0; idx < items.count; idx++)
{
UITabBarItem *barItem = [items objectAtIndex:idx];
barItem.tag = idx;
UIImage *selectedImage = [UIImage imageNamed:[selectedImages objectAtIndex:idx]];
UIImage *unSelectedImage = [UIImage imageNamed:[unSelectedImages objectAtIndex:idx]];
UIEdgeInsets inset = {
.top = 10,
.left = 0,
.bottom = -10,
.right = 0
};
barItem.imageInsets = inset;
[barItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unSelectedImage];
}
到目前爲止,這是工作精美。 。
這裏是哪裏出了問題進來。爲了讓我TabBarItem3鏈接到內容查看, 我實現下面的代碼在我TabBarClass:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (viewController.tabBarItem.tag == 1 || viewController.tabBarItem.tag == 2)
{
// Validating if is necesarry to replace the TabBarController.ViewControllers
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
MediaList *mediaView = [storyboard instantiateViewControllerWithIdentifier:@"SB_MediaList"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mediaView];
NSMutableArray *viewsArray = [NSMutableArray arrayWithArray:self.viewControllers];
if (viewController.tabBarItem.tag == 1)
{
//Setting the specfic data for my instance for tabBarItem 1
NSLog(@"Here we are in 1");
[mediaView setContent:@"Personalized content/data for TabBarItem 1"];
}
else if (viewController.tabBarItem.tag == 2)
{
//Setting the specfic data for my instance for tabBarItem 2
NSLog(@"Here we are in 2");
[mediaView setContent:@"Personalized content/data for TabBarItem 2"];
}
[viewsArray replaceObjectAtIndex:viewController.tabBarItem.tag withObject:navigationController];
self.viewControllers = viewsArray;
}
}
在此代碼的執行,我失去了圖片與項目2或3的自定義選項卡相關聯(取決於我選擇的項目)。
UPDATE
所以,我提出我的標籤欄的定製方法了我的委託,併成爲一個maintabbar類,我把它在viewDidLoad中和我的MEH HID didselectviewcontroller。這似乎解決了丟失圖像的問題,但是當單擊任一軟管項目時,在屏幕上產生了閃爍的不良副作用。我已經嘗試了不同的組合,從viewdidload方法中刪除它,因爲我們會,但仍然沒有運氣..
我已經採取了你的指導和感動一切。我更喜歡設計,但不幸的是閃爍問題依然存在。請參閱http://stackoverflow.com/q/19123984/2804909 – mday