moreNavigationController不显示即时图像

时间:2016-02-23 11:01:21

标签: ios objective-c uitableview uitabbar

我有一个正常工作的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];
    }
}

在此图片中,您可以看到正在发生的事情:

enter image description here

提前致谢。

1 个答案:

答案 0 :(得分:0)

正如我在这里看到的那样:

MoreNavigationController images disappearing on select

我已将此行添加到我的代码中:

navigationController.tabBarItem = vcCustom.tabBarItem;

感谢您的帮助。