storyboard問題

問題:
用Interface Builder為UITabBarController 設置selected image,運行起來后提示:Could not load the "(null)" image referenced from a nib in the bundle with identifier

Screen-Shot-2014-12-14-at-20.54.18.png

修改方法:
獲取制定的tabbar實例,用代碼修改
<pre><code>

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //storyboard每次都創建個新的實例對象,因此需要呈現它 否則不顯示
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"main" bundle:[NSBundle mainBundle]];
    UITabBarController * tabBarController = [storyboard instantiateViewControllerWithIdentifier:@"TabBarController"];
    self.window.rootViewController = tabBarController;

    NSArray *imageArray = @[@"ic_tabbar_home",@"ic_tabbar_oversea_red",@"ic_tabbar_faxian_red", @"ic_tabbar_shopping_cart", @"ic_tabbar_my"];
    int i = 0;
    NSArray *itemArray = tabBarController.tabBar.items;
    for (UITabBarItem *item in itemArray) {
    UIImage *image = [UIImage imageNamed:imageArray[i++]];
    item.selectedImage = image;
    }
    tabBarController.tabBar.tintColor = [UIColor redColor];

    return YES;
    }
    </code></pre>

參考:How to set selected images for UITabBarItem in UITabBarController

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容