我用 UIBarButtonItems 创建了一个 UIToolBar,但是当我点击它们时,没有调用选择器。任何帮助将不胜感激。
更新
根据评论中的建议,我修改了我的代码,但不幸的是,按钮仍然不起作用。
-(void)buildBottomMenu
{
UIImage *newsImg = [UIImage imageNamed:@"243-globe"];
UIBarButtonItem *newsBtnItem = [[UIBarButtonItem alloc] initWithImage:newsImg style:UIBarButtonItemStylePlain target:self action:@selector(loadHome)];
UIImage *weatherImg = [UIImage imageNamed:@"25-weather"];
UIBarButtonItem *weatherBtnItem = [[UIBarButtonItem alloc] initWithImage:weatherImg style:UIBarButtonItemStylePlain target:self action:@selector(loadWeather)];
UIImage *sportsImg = [UIImage imageNamed:@"63-runner"];
UIBarButtonItem *sportsBtnItem = [[UIBarButtonItem alloc] initWithImage:sportsImg style:UIBarButtonItemStylePlain target:self action:@selector(loadSports)];
UIImage *entrnImg = [UIImage imageNamed:@"178-city"];
UIBarButtonItem *entrnBtnItem = [[UIBarButtonItem alloc] initWithImage:entrnImg style:UIBarButtonItemStylePlain target:self action:@selector(loadEntertainment)];
UIImage *videoImg = [UIImage imageNamed:@"69-display"];
UIBarButtonItem *videoBtnItem = [[UIBarButtonItem alloc] initWithImage:videoImg style:UIBarButtonItemStylePlain target:self action:@selector(loadVideoPage)];
UIImage *moreImg = [UIImage imageNamed:@"259-list"];
UIBarButtonItem *moreBtnItem = [[UIBarButtonItem alloc] initWithImage:moreImg style:UIBarButtonItemStylePlain target:self action:@selector(loadOptionsPage)];
UIBarButtonItem* flexibleSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
[_bottomBar setItems:[NSArray arrayWithObjects:flexibleSpace,newsBtnItem,flexibleSpace,
weatherBtnItem,flexibleSpace,
sportsBtnItem,flexibleSpace,
entrnBtnItem,flexibleSpace,
videoBtnItem,flexibleSpace,
moreBtnItem,flexibleSpace,
nil]];
[self.view addSubview:_bottomBar];
}
这是一个示例选择器:
- (void)loadWeather
{
NSLog(@"Loading weather");
}