iOS 5:UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage:not working/ignored

tab*_*ber 1 iphone uitabbaritem uitabbar ios ios5

根据Apple 文档

我正在尝试在UITabBarItem上设置自定义完成的已选择和未选择的图像,如下所示:


...
DetailViewController *vc1 = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
UITabBarItem *vc1i = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:100];
[vc1i setFinishedSelectedImage:[UIImage imageNamed:@"tab_bar_item_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_bar_item_normal.png"]];
[vc1 setTabBarItem:vc1i];
...
Run Code Online (Sandbox Code Playgroud)

基本上正在发生的事情是TabBar加载得很好,它只是完全忽略了标签栏项目的自定义.

我的目标是iOS5 +

图像是30x30透明PNG并存在于项目中.无法弄清楚我在这里俯瞰什么,但一定是什么东西!

这是在tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath方法中调用的,ala Ray Wenderlich的教程

有人有主意吗?

谢谢!

Nic*_*idt 6

标签栏项目使用以下方法初始化:initWithTabBarSystemItem:tag:.但是,正如文件所说:

此方法返回系统提供的选项卡栏项.稍后无法更改返回项目的标题和图像属性.

您应该使用标签栏项初始化initWithTitle:image:tag:.

UITabBarItem *vc1i = [[UITabBarItem alloc] initWithTitle:@"Top Rated" image:nil tag:100];
[vc1i setFinishedSelectedImage:[UIImage imageNamed:@"tab_bar_item_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_bar_item_normal.png"]];
Run Code Online (Sandbox Code Playgroud)