moreNavigationController 暂时不显示图像
Posted
技术标签:
【中文标题】moreNavigationController 暂时不显示图像【英文标题】:moreNavigationController not displaying image for an instant 【发布时间】:2016-02-23 11:01:21 【问题描述】:我有一个正常工作的 UITabBar,但是当我添加更多元素并且出现更多按钮时,它显示出一种奇怪的行为。
如果我选择一个项目,然后再次按“更多”按钮返回,则所选项目会在几秒钟内不显示图像,然后再次显示。
我以编程方式创建了 UITabBar,并以编程方式将 moreNavigationController 颜色的 UITableView 更改为。
如果我删除 moreNavigationController 的个性化,行为就会出现。
我的第一个猜测是 UITabBar 的色调(白色),但我将其更改为红色并且行为是相同的。
然后我虽然是图像,但未选择的图像是灰色的,选择的图像是蓝色的。
这是我用来创建 UITabBar 的代码:
- (void)createTabBar
tabController = [self.storyboard instantiateViewControllerWithIdentifier:@"cCustomTabController"];
dValue = [dConfiguration objectForKey:@"Buttons"];
NSMutableArray *aControllers = [[NSMutableArray alloc] init];
int i = 0;
for (NSString* sProperty in dValue)
NSString* d = @"Details";
NetworkStatus internetStatus = [_reachabilityInfo currentReachabilityStatus];
NSData *itemData = Nil;
if (internetStatus != NotReachable)
itemData = [util getSpecificJsonData:[sProperty valueForKeyPath:@"Item"]];
if(itemData != nil)
UIStoryboard *aStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
UIViewController *vcCustom = [aStoryboard instantiateViewControllerWithIdentifier:[util getControllerName:[sProperty valueForKeyPath:@"ViewController"]]];
[vcCustom setValue:itemData forKey:@"JsonData"];
[vcCustom setValue:[sProperty valueForKeyPath:@"Item"] forKey:@"Item"];
[vcCustom setValue:d forKey:@"Details"];
[util saveJSON:itemData withName:[NSString stringWithFormat:@"%@%@",[sProperty valueForKeyPath:@"Item"],[CommonsUtils getCommonUtil].getAppLanguage]];
[[vcCustom navigationController] setNavigationBarHidden:NO animated:NO];
vcCustom.navigationItem.leftBarButtonItem = Nil;
vcCustom.navigationItem.hidesBackButton = YES;
UIImage *imageBtn = [self changeImageSize:[UIImage imageNamed:[util getImageName:[sProperty valueForKeyPath:@"Image"] andRetrina:[sProperty valueForKeyPath:@"ImageRetina"]]] scaledToSize:CGSizeMake(30, 30)];
UIImage *imageBtnPress = [self changeImageSize:[UIImage imageNamed:[util getImageName:[sProperty valueForKeyPath:@"ImageHeighlighted"] andRetrina:[sProperty valueForKeyPath:@"ImageRetinaHeighlighted"]]] scaledToSize:CGSizeMake(30, 30)];
UITabBarItem *tab = [[UITabBarItem alloc] initWithTitle:[sProperty valueForKeyPath:@"Title"] image:imageBtn selectedImage:imageBtnPress];
UIImage * iSelected = imageBtnPress;
iSelected = [iSelected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[tab setSelectedImage:iSelected];
tab.tag = i;
if([[sProperty valueForKeyPath:@"Title"] isEqualToString:@"Notificaciones"])
tab.badgeValue=[sProperty valueForKeyPath:@"Badge"];
[vcCustom setTabBarItem:tab];
[vcCustom setTitle:[sProperty valueForKeyPath:@"Title"]];
UINavigationController *navigationController = [[cCustomNavigationController alloc] initWithRootViewController:vcCustom];
navigationController.navigationBar.tintColor = NAVBAR_TINTCOLOR;
UIColor *uicText = NAVBAR_TEXTCOLOR;
navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:uicText forKey:NSForegroundColorAttributeName];
[aControllers insertObject:navigationController atIndex:i];
i++;
tabController.delegate = self;
tabController.viewControllers = aControllers;
tabController.tabBar.tintColor = TABBAR_TINTCOLOR;
UIColor *uicTabBar = TABBAR_BACKGROUND_COLOR;
[[UITabBar appearance] setBarTintColor:uicTabBar];
tabController.customizableViewControllers = @[];
tabController.moreNavigationController.navigationBar.tintColor = NAVBAR_TINTCOLOR;
UIColor *uicText = NAVBAR_TEXTCOLOR;
tabController.moreNavigationController.navigationBar.barTintColor = NAVBAR_BACKGROUND_COLOR;
tabController.moreNavigationController.navigationBar.translucent = YES;
tabController.moreNavigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:uicText forKey:NSForegroundColorAttributeName];
这就是我个性化 moreNavigationController 的 UITableView 的方式:
UITableView *tView = (UITableView*)tabController.moreNavigationController.topViewController.view;
if ([[tView subviews] count])
for (UITableViewCell *cCell in [tView visibleCells])
cCell.textLabel.textColor = TABLECELL_TEXT_COLOR;
cCell.textLabel.highlightedTextColor = TABLECELL_TEXT_COLOR_HIGHLIGHTED;
cCell.contentView.backgroundColor = TABLECELL_BACKGROUND_COLOR;
cCell.backgroundColor = TABLECELL_BACKGROUND_COLOR;
UIView * selectedBackgroundView = [[UIView alloc] init];
UIColor *uicCell = TABLECELL_BACKGROUND_COLOR_SELECTED
[selectedBackgroundView setBackgroundColor:uicCell];
[cCell setSelectedBackgroundView:selectedBackgroundView];
在这张图片中,您可以看到正在发生的事情:
提前致谢。
【问题讨论】:
【参考方案1】:正如我在这里看到的:
MoreNavigationController images disappearing on select
我已将这一行添加到我的代码中:
navigationController.tabBarItem = vcCustom.tabBarItem;
感谢您的帮助。
【讨论】:
以上是关于moreNavigationController 暂时不显示图像的主要内容,如果未能解决你的问题,请参考以下文章
MoreNavigationController 的背景图片
moreNavigationController 暂时不显示图像
从 UITabBarController 的 moreNavigationController 中移除 rightBarButtonItem