-[NSCFString objectAtIndex:]:无法识别的选择器 [英] -[NSCFString objectAtIndex:]: unrecognized selector

查看:69
本文介绍了-[NSCFString objectAtIndex:]:无法识别的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Google中找不到的小问题:
UITableView 可以正常工作,直到开始滚动为止。

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 `

方法:

- (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!

编辑:
myArray只是正常的 NSArray * myArray
这是一个排序的数组->

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)是XML解析器的结果。希望您能看到我的问题。 。

resultArray (NSMutableArray) is the Result of an XML-Parser.. hope you can see my problem..

推荐答案

这意味着您正在发送 objectAtIndex:消息到类型为 NSString (或可能为 CFString )的对象。当然,您期望 myArray 是一个数组而不是字符串。

It means that you're sending an objectAtIndex: messages to an object of type NSString (or possibly CFString). Of course you're expecting myArray to be an array and not a string.

可能发生的事情是数组被释放(几乎肯定是自动释放)的时间过早,并且到了上述方法被称为 的内存被 myArray 指向时现在拥有一个字符串。

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 myArray now holds a string.

为响应您的编辑...

这行:

myArray = [resultArray sortedArrayUsingDescriptors:sortDescriptors];

...不正确。该值是自动释放的。您需要保留它:

...is incorrect. The value is autoreleased. You need to retain it:

myArray = [[resultArray sortedArrayUsingDescriptors:sortDescriptors] retain];

请记住在关闭视图之前将其释放!

Remember to release it before you close the view!

这篇关于-[NSCFString objectAtIndex:]:无法识别的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆