2012-03-04 29 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