IOS [__NSCFConstantString size]: unrecognized selector sent to instance 错误

释放双眼,带上耳机,听听看~!

因为使用时候的类型和初始化的对象类型不匹配造成的,例如

- (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;
        }

 

人已赞赏
iOS文章

ios实现UISearchBar的Placeholder居左显示

2020-3-30 3:16:48

iOS文章

iOS开发 - touchBegan事件判断点击的位置在View上还是在View的子View上

2020-3-30 4:31:56

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索