因为使用时候的类型和初始化的对象类型不匹配造成的,例如
- (NSMutableDictionary *)getMenuItems
{
NSArray *defaultTmp = [NSArray arrayWithObjects:@"menu_friend_icon@2x.png",@"menu_message_icon@2x.png", @"menu_announcemen_icon@2x.png",@"menu_album_icon@2x.png",@"menu_more_icon@2x.png",nil];
self.menuitemDefaultImages = defaultTmp;
NSArray *highlightTmp = [NSArray arrayWithObjects:@"menu_friend_onfocus_icon@2x.png",@"menu_message_onfocus_icon@2x", @"menu_announcemen_onfocus_icon@2x",@"menu_album_onfocus_icon@2x.png",@"menu_more_onfocus_icon@2x.png",nil];
self.menuitemHighlightImages = highlightTmp; //这里都是nsstring类型的名字
NSArray *labelTmp = [NSArray arrayWithObjects:@"好友",@"消息", @"公告",@"相册",@"更多",nil];
self.menuitemLabels = labelTmp;
NSMutableDictionary *tmp = [NSMutableDictionary dictionary];
[tmp setObject:self.menuitemDefaultImages forKey:@"Default"];
[tmp setObject:self.menuitemHighlightImages forKey:@"Highlight"];
[tmp setObject:self.menuitemLabels forKey:@"Labels"];
self.menuitemDictionary = tmp;
return self.menuitemDictionary;
}
self.selectedStatuImages = [[self.announce getMenuItems]objectForKey:@"Highlight"];
switch (button.tag) {
case 0: //friends
{
self.friendBtn.selected = !self.friendBtn.selected;
if (self.friendBtn.selected) {
[self.friendBtn setImage:[self.selectedStatuImages objectAtIndex:0] forState:UIControlStateSelected]; //这里获取时候的setimage参数却是UIImage类型的,所以会报错。要修改成[button setBackgroundImage:[UIImage imageNamed:[self.normalStatuImages objectAtIndex:index]] forState:UIControlStateNormal];
}else{
[self.friendBtn setImage:[self.normalStatuImages objectAtIndex:0] forState:UIControlStateNormal];
}
break;
}