MohamMad Salah
MohamMad Salah

Reputation: 981

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];

Upvotes: 3

Views: 4763

Answers (2)

zeeawan
zeeawan

Reputation: 6905

I was getting the same exception on line

 if(self.arrTypes != nil)

cause of the following line being used at a different place in code

 [self.arrTypes release];

and replacing this code with

 self.arrTypes = nil;

resolved the issue.

Upvotes: 0

Serdar Dogruyol
Serdar Dogruyol

Reputation: 5157

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]

Upvotes: 11

Related Questions