• [__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;
            }
                


  • 相关阅读:
    【刷题-LeetCode】154 Find Minimum in Rotated Sorted Array II
    【刷题-LeetCode】153 Find Minimum in Rotated Sorted Array
    【刷题-LeetCode】152 Maximum Product Subarray
    迭代器,生成器
    python 16 装饰器
    python 15 闭包函数
    python 14 名称空间与作用域
    函数参数
    python 11 函数基础
    python中list、tuple、set、dict区别
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3401240.html
Copyright © 2020-2023  润新知