2012-03-04 21 views
0

在我的ViewController,我想補充的uitabbarUITabBarItem調用init函數,但標記爲空

UITabBar *tabBar = [[UITabBar alloc]initWithFrame:CGRectMake(0, 410, 320, 50)]; 
    UITabBarItem *item0 = [[UITabBarItem alloc]initWithTitle:@"first" image:[UIImage imageNamed:@"FirstTab.png"] tag:0]; 
    NSLog(@"item0.title = %@",item0.title); 
    NSLog(@"item0.tag = %@",item0.tag); 
    UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"second" image:[UIImage imageNamed:@"SecondTab.png"] tag:1]; 
    UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"third" image:[UIImage imageNamed:@"ThirdTab.png"] tag:2]; 
    UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"forth" image:[UIImage imageNamed:@"ForthTab.png"] tag:3]; 
    UITabBarItem *item4 = [[UITabBarItem alloc]initWithTitle:@"fifth" image:[UIImage imageNamed:@"FifthTab.png"] tag:4]; 
    tabBar.delegate = self; 
    NSArray *array = [[NSArray alloc]initWithObjects:item0,item1,item2,item3,item4, nil]; 
    [tabBar setItems:array animated:NO]; 
    [tabBar setSelectedItem:item0]; 

    [self.view addSubview:tabBar]; 
    [tabBar release]; 

,這是我的日誌:

2012-03-04 10:38:54.839 MagicWords[1265:f803] item0.title = first 
2012-03-04 10:38:54.840 MagicWords[1265:f803] item0.tag = (null) 

所以我ploblem的是,爲什麼標籤空,但標題是正確的。 預先感謝您。

回答

2

標籤的類型是NSInteger,所以你應該使用%d將其打印出來:

NSLog(@"item0.tag = %d",item0.tag); 
+0

謝謝你,你是對的... – Tan 2012-03-04 02:55:06

相關問題