unrecognized selector sent to instance

 

[iOS] Error Fixed : [__NSArrayI addObject:]: unrecognized selector sent to instance

當我建立了一個NSMutableArray 對象的時候atom

 

@property (nonatomic,copy)NSMutableArray *children;spa

而後經過addObject運行就會報錯,[__NSArrayI addObject:]: unrecognized selector sent to instance

 

解決方式:對象

一、經過理解,咱們知道addObject後的array實際上是變了,可能內存變大了,你能夠理解成這個對象已經不是原來的了,就至關於沒有定義一個具體實例對象同樣。但經過@synthesize 默認的setter不能保證copy就必定等於mutableCopy;因此咱們須要自定義本身的setter方法。內存

例如個人定義,在.m中增長咱們本身定義的setter方法,讓它進行mutableCopy便可。it

 

-(void)setChildren:(NSMutableArray*) array{table

    if(children != nil)class

    {select

        children = nil;方法

    }tab

    children = [array mutableCopy];

}

二、把copy變成retain,由於不是copy建立新內存和新賦值的話,原有實例對象就不會「全新」致使unrecognized selector sent to instance。
相關文章
相關標籤/搜索