1

4つのタブを持つios 6をターゲットとするユニバーサルタブ付きアプリがあります。リリースの準備がほぼ整い、iAds をサポートする最新かつ最高の方法を検討し始めました。Apple の iAdSuite デモ プロジェクトを見てみると、BannerViewController を使用して 4 つの UIViewController をラップすることが完璧な解決策のように思えます。

そして、iAd を正しく表示するという点で完璧に機能します。

ただし、変更を加えてから、タブバーに画像/アイコンが表示されなくなりました。BannerViewController コードを 1 行ずつ調べましたが、画像設定をオーバーライドしているように見えるものは何も表示されません。

私が行った変更は次のとおりです。

  1. プロジェクトに BannerViewController.h & .m を追加します。
  2. #import < iAd/iAd.h> を 4 つの UIViewController のそれぞれに追加します。
  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 をターゲットにしています。

4

2 に答える 2

1

それで、私は最終的に解決策を見つけました。このSOの質問のおかげで、関連性のあるものでした...

iOS UITabBar の UITabBarButton のフレームを変更

ビュー コントローラーから画像設定コードを削除し、代わりにビュー コントローラーが 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"]];

そして今、私のタブバーの画像が戻ってきました!

于 2013-02-27T13:37:26.180 に答える
0

私はちょうどこの同じ問題にぶつかりました。原因は、各 ViewController をラップする BannerViewController が tabBarItem へのアクセスを通過しないため、UITabBarController が必要なアイコンを見つけられないことです。

正しい修正は、これを BannerViewController.m に追加することです。

- (UITabBarItem *)tabBarItem {
  return _contentController.tabBarItem; 
}
于 2015-04-20T19:28:52.190 に答える