iPhone以编程方式实例化UITabBarItem [英] iPhone instantiating a UITabBarItem programmatically

查看:49
本文介绍了iPhone以编程方式实例化UITabBarItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽我所能,我无法使它正常工作.这是我最近的尝试.有人可以告诉我为什么这行不通吗?

Try as I might, I cannot get this to work. Here is my latest attempt. Can someone clue me in as to why this does not work?

在我的视图控制器的init方法调用的方法中:

In a method which is called by my view controller's init method:

UIImage *image = [UIImage imageNamed: @"window22.png"];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle: @"Some Title" image: image tag: 0];
self.tabBarItem = item;

它所做的只是在应该放置图像的地方放一个大正方形.标签栏中的标题与视图控制器的标题相同.

All it does is put a big square where the image should be. The title in the tab bar remains the same as the view controller's title.

这里所有的内容都以编程方式实例化,包括标签栏控制器.

Everything is being instantiated programmatically here, including the tab bar controller.

推荐答案

根据

According to the docs, the tabBarItem will be instantiated automatically- you don't need to create it yourself. When I've set the title and image in the tabBar for a view controller, I've used

self.tabBarItem.image = [UIImage imageNamed:imageName];

这篇关于iPhone以编程方式实例化UITabBarItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆