开发者

getting the error [NSCFString setBackgroundImage:forState:]:

开发者 https://www.devze.com 2023-01-27 03:47 出处:网络
i am getting the following error while adding the background imageto the content of a table view cell

i am getting the following error while adding the background image to the content of a table view cell

 [NSCFString setBackgroundImage:forState:]: unrecognized selector sent to instance

    UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            playBtn.frame = CGRectMake(x+playBtnXPos, y+playBtnYPos, playBtnWidth, playBtnHeight); 
            [playBtn addTarget:self action:@selector(playBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
            if(playingButton && streamer){
                if(playingButtonTag == i && [streamer isPlaying]){
                    [playBtn setBackgroundImage:[UIImage imageNamed:pauseBtnimgName] forState:UIControlStateNormal];
           开发者_开发技巧         playingButton = playBtn;
                }else [playBtn setBackgroundImage:[UIImage imageNamed:playBtnimgName] forState:UIControlStateNormal];
            }else [playBtn setBackgroundImage:[UIImage imageNamed:playBtnimgName] forState:UIControlStateNormal];
            playBtn.tag = i;

            [cell.contentView addSubview:playBtn];

.....

can anybody help me out...

thanks...


When you have memory management issues (selectors being sent to the wrong instances is a sign of memory management issues), there are a number of things you can do:

  1. Re-read the Cocoa memory management rules and make sure that you're following them.
  2. Run the static analyser. This will often pick up places where you have neglected the memory management rules.
  3. Try using NSZombieEnabled to find out whether [and when] you are sending messages to unallocated instances.


The runtime is saying it all: You're trying to call something in NSString that doesn't exist, and I know for sure that [NSCFString setBackgroundImage:forState:] does not exist, hence the error and "possibly" a crash. The compiler should show you a warning in your source code where you're going wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消