Do what @rmaddy suggested or:
Change:
[results addObject:@[recipe]];
to:
[results addObject:recipe]
Explanation:
NSInvalidArgumentException', reason: '-[__NSArrayI length : unrecognized selector sent to instance
This error tells us:
- Object is an
NSArray
(somewhere, somehow)
- Method called on this
NSArray
object was length
- But
NSArray
does not have a length
method
- It seems somewhere a call to
length
method was sent, most probably on an NSString
object that is actually holding an NSArray
object rather than an NSString
object.
Firstly note that when you specify:
@[]
So when you do: [results addObject:@[recipe]];
:
@[recipe]
is equivalent to
[NSArray alloc] initWithObjects:recipe, nil]
So... you're basically taking recipe
, putting it in an array, then adding this array object within results
(which is another array).
Later when you come to PageView
[[self.filteredContent objectAtIndex:indexPath.row] valueForKey:@"recipeName"];
will return you an array of values for the key recipeName
.
So basically, your string is holding an array and not the string object.
Now... whether you called length
on it or not, somewhere in the lifecycle, length
is being called on cell.textLabel.text
and raising this error.