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

2024-05-26

我有一个小问题,在谷歌中找不到:UITableView工作正常,直到我开始滚动。

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

只是猜测这是“问题”方法......如果您需要更多信息:请告诉我:) 感谢你的帮助!

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

   NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lesson" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
myArray = [resultArray sortedArrayUsingDescriptors:sortDescriptors];

resultArray (NSMutableArray) 是 XML 解析器的结果..希望你能看到我的问题..


这意味着您要发送objectAtIndex:发送给 type 对象的消息NSString(或者可能CFString)。你当然期待myArray是一个数组而不是一个字符串。

可能发生的情况是您的数组被释放(几乎肯定是自动释放)太早,并且当上面的方法被称为内存时was被人指着myArray现在持有一个字符串。

响应您的编辑...

这行:

myArray = [resultArray sortedArrayUsingDescriptors:sortDescriptors];

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

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

记得在关闭视图之前释放它!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

-[NSCFString objectAtIndex:]:无法识别的选择器 的相关文章

随机推荐