Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

message sent to deallocated instance ,,, [__NSArrayI respondsToSelector:]

I have this implementation file with aNSArray object userIDs

NSArray *userIDs;
NSInteger friendID;

@implementation TableViewController

-(void)reciveFriendsIDs:(NSArray *)array
 {
userIDs = [NSArray arrayWithArray:array];
 }

-(NSString *)getFriendId
{
 return [userIDs objectAtIndex:friendID];
}
.
.
.
@end

and the method -(NSString *)getFriendId call it from another class like this :

TableViewController *tableController = [[TableViewController alloc]init];
NSString *fid = [tableController getFriendId];

But I am having an error said "-[__NSArrayI respondsToSelector:]: message sent to deallocated instance 0x20320200" and the compiler indicate the error in this line:

return [userIDs objectAtIndex:friendID];
like image 851
MohamMad Salah Avatar asked Sep 11 '26 07:09

MohamMad Salah


1 Answers

You are allocating the NSArray with arrayWithArray static method.

In this way it's getting added in the auto release pool and the retain count will be 0. Either retain it or manually alloc it with [[NSArray alloc] init]

like image 192
Serdar Dogruyol Avatar answered Sep 12 '26 22:09

Serdar Dogruyol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!