Reputation: 166
getting a "Thread 1: EXC_BAD_ACCES(code=2, adress=0xbf7fffffc)" error at
NSArray *tempArray ] [lijstString componentsSeperatedByString:@","];
What can i do about this?
This is the whole codepart:
-(NSMutableArray *)lijstArray{
NSString *lijstString = self.details[@"lijst"];
NSArray *tempArray = [lijstString componentsSeparatedByString:@", "];
self.lijstArray = [NSMutableArray array];
for (NSString *lijstValue in tempArray) {
[self.lijstArray addObject:[lijstValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}
return self.lijstArray;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
Upvotes: 0
Views: 88
Reputation: 5665
Your lijstArray
getter function is infinitely recursive. Assuming lijstArray is an @property, every time you use self.lijstArray
you are calling the instance method lijstArray
if used as a getter or setLijstArray
if used as a setter.
You are using self.lijstArray
three times. The first use on the left part of the assignment operator is only calling [self setLijstArray: ... ]
so while that will trample the _lijstArray
iVar, it will not cause recursion.
You cause recursion in two places, though once is enough. First is with [self.lijstArray addObject: ... ]
which is the same as [[self lijstArray] addObject: ... ]
. This causes infinite recursion.
And then with return self.lijstArray
which is the same as return [self lijstArray]
-- again the lijstArray instance method is calling itself. This also causes infinite recursion.
Incidentally the stack trace would be informative-- you'd have a very deep stack.
Upvotes: 1
Reputation: 2768
try this:
-(NSMutableArray *)lijstArray{
if(!_lijstArray){ //If you need get new lijstArray always, comment this line, and below "}"
NSString *lijstString = self.details[@"lijst"];
NSArray *tempArray = [lijstString componentsSeparatedByString:@", "];
_lijstArray = [NSMutableArray array];
for (NSString *lijstValue in tempArray) {
[_lijstArray addObject:[lijstValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}
}
return _lijstArray;
}
Upvotes: 0
Reputation: 364
Check to make sure the line:
self.details[@"list"];
Is not null. Also check to make sure tempArray and lijstString are being allocated and initialized.
Upvotes: 0