I have this little problem I couldn’t find in Google:
UITableView works fine until I start scrolling.
Error Message: `-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x5f24870 `
Method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length]-1];
//populate cell
cell.textLabel.text = [[myArray objectAtIndex: storyIndex] objectForKey: @"subject"];
return cell;
}
Just guessed that was the “problem”-method… if you need more infos: please tell me 🙂
thanks for all your help!
EDIT:
myArray is just the normal NSArray *myArray
It’s a sorted Array ->
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lesson" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
myArray = [resultArray sortedArrayUsingDescriptors:sortDescriptors];
resultArray (NSMutableArray) is the Result of an XML-Parser.. hope you can see my problem..
It means that you’re sending an
objectAtIndex:messages to an object of typeNSString(or possiblyCFString). Of course you’re expectingmyArrayto be an array and not a string.What probably happened is that your array is being released (almost certainly autoreleased) too early and that by the time the method above is called the memory that was being pointed at by
myArraynow holds a string.In response to your edit…
This line:
…is incorrect. The value is autoreleased. You need to retain it:
Remember to release it before you close the view!