cellForRowAtIndexPath: crashes when trying to access arrays objectAtIndex:indexPath.row

醉酒当歌 提交于 2019-12-02 06:19:28

The actual error is this:

-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x5d10c20

In other words, you tried to run objectAtIndex: on an NSString (NSCFString), which of course does not support this method.

You call objectAtIndex: three times, in these lines:

cell.titleLabel.text = [postsArrayTitle objectAtIndex:indexPath.row];
cell.dateLabel.text = [postsArrayDate objectAtIndex:indexPath.row];
cell.cellImage.image = [UIImage imageWithContentsOfFile:[postsArrayImg objectAtIndex:indexPath.row]];

So it appears that postsArrayTitle, postsArrayDate, or postsArrayImg isn't an NSArray, but an NSString.

** I had the same issue, addressing the "self." array fixed it. **


The NSArray was only representing the singular instance of the "ObjectAtIndex:#" which ultimately was being treated as a NSString. When creating the NSArray, I created tempArray, filled it with objects, set it equal to MyArray, the released tempArray. But setting it equal to "MyArray = tempArray;" failed. Required to address the array OBJECT with "self.MyArray = tempArray;" which works 100% !!
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!