zoukankan      html  css  js  c++  java
  • [__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;
            }
                


  • 相关阅读:
    代理模式
    适配器模式
    原型模式
    创建者模式
    装饰模式
    web总结
    4.14
    4.14
    POJ2385
    POJ2229
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3401240.html
Copyright © 2011-2022 走看看