2013-02-27 59 views
1

我有一個通用的標籤式應用程序,目標是具有4個選項卡的ios 6。幾乎準備發佈,我開始研究支持iAd的最新和最好的方法。看過Apple的iAdSuite演示項目後,看起來好像使用BannerViewController來包裝我的4個UIViewControllers是一個完美的解決方案。當使用BannerViewController時沒有UITabBarItem圖像

它正確地顯示iAds的功能非常完美。

但是,由於進行更改我的標籤欄不再顯示圖像/圖標。我已經逐行瀏覽了BannerViewController代碼,但看不到任何似乎覆蓋圖像設置的內容。

我所做的改變是:

  1. 添加BannerViewController.h & .M到我的項目。
  2. #import < iAd/iAd.h>在我的每個UIViewControllers中。
  3. 修改,如此,它改變設置我的標籤視圖控制器的AppDelegate代碼:從

    self.tabBarController = [[UITabBarController alloc] init]; 
    self.tabBarController.delegate = self; 
    self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4]; 
    

self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.delegate = self; 
self.tabBarController.viewControllers = @[ 
       [[BannerViewController alloc] initWithContentViewController:viewController1], 
       [[BannerViewController alloc] initWithContentViewController:viewController2], 
       [[BannerViewController alloc] initWithContentViewController:viewController3], 
       [[BannerViewController alloc] initWithContentViewController:viewController4] 
       ]; 

在我的每個4個視圖控制器的我initWithNibName方法中的以下代碼(使用適當的標題和圖像名稱:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Library", @"Library"); 
     self.tabBarItem.image = [UIImage imageNamed:@"96-book"]; 
    } 
    return self; 
} 

使用原始代碼,標題和圖像按預期工作。使用修改後的代碼,我得到標題,但沒有圖像,只是一個黑色的按鈕。有沒有人遇到過這個?

注意我在Apple示例應用程序中嘗試了這一點,無法獲取圖像以顯示那裏,示例應用程序目標iOS5和我的應用程序目標iOS6。

回答

1

所以最後找到了解決,由於這太問題這是排序的相關...

iOS Change frame of UITabBarButton in UITabBar

我除去圖像從視圖控制器設置碼,而是增加了以下行到視圖控制器被分配到UITabBar後的AppDelegate

UITabBar *tabBar = self.tabBarController.tabBar; 
[[tabBar.items objectAtIndex:0] setImage:[UIImage imageNamed:@"253-person"]]; 
[[tabBar.items objectAtIndex:1] setImage:[UIImage imageNamed:@"138-scales"]]; 
[[tabBar.items objectAtIndex:2] setImage:[UIImage imageNamed:@"85-trophy"]]; 
[[tabBar.items objectAtIndex:3] setImage:[UIImage imageNamed:@"96-book"]]; 

現在我的標籤欄圖像回來了!

0

我剛剛遇到了同樣的問題。 原因是包裝每個ViewControllers的BannerViewController沒有通過對tabBarItem的訪問,所以UITabBarController找不到它需要的圖標。

正確的解決方法是把它添加到BannerViewController.m:

- (UITabBarItem *)tabBarItem { 
    return _contentController.tabBarItem; 
}