2014-08-28 46 views
0

我想要做的是在我的iOS應用中自定義UITabBarItem的文本和圖像。我想我可以通過UITabBarControllerCustomTabBar這個類來做到這一點。在「CustomTabBar」類型的對象上找不到屬性「窗口」

當我嘗試使用下面的代碼執行操作時,出現錯誤消息:Property 'window' not found on object of type 'CustomTabBar'。如何正確劃分UITabBarController的子類,以便我可以自定義文本和圖像?

CustomTabBar.h:

#import <UIKit/UIKit.h> 
#import <Parse/Parse.h> 
#import <Parse/PFCloud.h> 

@interface CustomTabBar : UITabBarController 

@end 

CustomTabBar.m:

#import "CustomTabBar.h" 

@interface CustomTabBar() 

@end 

@implementation CustomTabBar 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    // Assign tab bar item with titles 
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 
    UITabBar *tabBar = tabBarController.tabBar; 
    UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; 
    UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1]; 

    tabBarItem1.title = @"Search"; 
    tabBarItem2.title = @"MatchCenter"; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

回答

2

您發佈的代碼是在你的標籤欄控制器的子類,所以標籤欄控制器是隻是「自」。

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UITabBar *tabBar = self.tabBar; 
    UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; 
    UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1]; 

    tabBarItem1.title = @"Search"; 
    tabBarItem2.title = @"MatchCenter"; 
} 
相關問題