我已经创建了一个没有UITabBarController的UITabBar和UITabBarItems,现在我想知道如何在点击UITabBarItem.What时放置一个动作UITabBarItem是我应该使用的方法吗?
发布于 2010-03-26 08:20:21
您不能直接在UITabBarItem对象上设置操作。相反,视图控制器应该实现以下UITabBarDelegate方法:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;当用户选择一个选项卡(即UITabBarItem)时,将调用此方法。
发布于 2010-03-25 14:20:22
你在用UINavigationController吗?如果是这样的话,从活动的视图控制器子类中获取navigationItem并向其添加按钮,例如:
- (void) viewWillAppear:(BOOL)animated;
{
[super viewWillAppear: animated];
UIBarButtonItem * leftButtonItem = [[[UIBarButtonItem alloc] initWithTitle: @"Don't Show Again" style: UIBarButtonItemStyleBordered target: self action: @selector(permanentlyCloseWelcomeView)] autorelease];
[[self navigationItem] setLeftBarButtonItem: leftButtonItem];
}发布于 2010-07-12 07:38:16
你能使用UIToolbar和UIBarButtonItem的实例来代替吗?它可以更简单明了。
toolBar = [[UIToolbar alloc] init];
newPlayerItem = [[UIBarButtonItem alloc] initWithTitle:@"+"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(newPlayer:)];
NSArray *toolBarItemsArray = [[NSArray alloc] initWithObjects:newPlayerItem, nil];
[toolBar setItems:toolBarItemsArray];
[toolBarItemsArray release];https://stackoverflow.com/questions/2513353
复制相似问题