我的应用中有很多标签。标签工作没有问题,但我收到一些警告信息(在上面的标题中),我想摆脱它。我的代码如下:
-(void)pressItem1:(id)sender {
[self presentModalViewController:settingsViewController animated:YES];
}
-(void)pressItem2:(id)sender {
[self presentModalViewController:infoViewController animated:YES];
}
-(void)pressItem3:(id)sender {
[self presentModalViewController:aboutViewController animated:YES];
}
-(void)viewDidLoad {
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]];
CGRect frame = CGRectMake(0, 0, 480, 49);
UIView *v = [[UIView alloc] initWithFrame:frame];
UIImage *i = [UIImage imageNamed:@"smallMenuBackground.png"];
UIColor *c = [[UIColor alloc] initWithPatternImage:i];
v.backgroundColor = c;
[c release];
[mainTabBar insertSubview:v atIndex:0];
[v release];
[settingsBarItem setAction:@selector(pressItem1:)];
[infoBarItem setAction:@selector(pressItem2:)];
[aboutBarItem setAction:@selector(pressItem3:)];
//initialSyncSwitch = NO;
[super viewDidLoad];
}
选项卡正在运行,但可能有更好的方法,因此我不会收到这些警告。
此致 斯蒂芬
答案 0 :(得分:2)
您不直接在UITabBarItem
上设置操作。相反,您应该在创建它的UITabBarDelegate
中实施UIViewController
。具体而言,代表应实施:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
在此处,您可以根据传递的pressItem1
来调用pressItem2
,item
等。