in my viewcontroller,I want to add the uitabbar
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];
and this is my log:
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)
so my ploblem is why the tag is null,but the title is right.
thank you in advance.
tag’s type is
NSInteger, so you should use%dto print it: