我试图从文件路径组件创建一个数组。我的文件路径的数组(如NSString的),我通过他们循环,再破每下跌,像这样:Objective-C:从NSString制作NSArray
//get the array of image paths
imageList = [[notification userInfo] objectForKey:@"images"];
//loop through the array and get the image names
for (NSString* thisImagePath in imageList) {
NSArray* thisImagePathArray = [thisImagePath componentsSeparatedByString:@"/"];
可以说,我计划在这里崩溃的时间。我收到以下错误消息:
-[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1a7940
imageList是放入视图的文件数组。因为这个问题开始出现,我一次只删除一个文件。例如:
这个文件没有工作:
/Users/steve/Desktop/thinkstock/PT121211_PI_bariatric.tif
这确实
/Users/steve/Desktop/thinkstock/Studentexhausted82557038.jpg
所以,如果我理解正确的错误消息,我想给componentsSeparatedByString选择应用到一个NSArray,不支持该选择器。但在我的循环中,我正在调用NSString,如果对象是一个数组,我不应该在那里崩溃? (并且我99%确定imageList的索引0处的对象是一个字符串。)
我的目标是从文件路径获取文件名,有没有比我采用的方法更好的方法?
当我通过(把一个调试点似乎工作,我策划了componentsSeparatedByString线步骤:
但如果我打继续它崩溃
至于建议我改变。我的代码来记录数据:
//loop through the array and get the image names
for (NSString* thisImagePath in imageList) {
if (![thisImagePath isKindOfClass:[NSString class]]) {
NSLog(@"The class of this object is: %@", [thisImagePath className]);
}
NSLog(@"%@", thisImagePath);
NSArray* thisImagePathArray = [thisImagePath componentsSeparatedByString:@"/"];
NSString* thisImageName = [thisImagePathArray objectAtIndex:[thisImagePathArray count]-1];
类检查的条件永远不会被触发,因为一切都是NSS特级。然而,一些文件的工作,一些不...
2012-01-19 13:59:04.631 archiveDrop_cocoa[76758:10b] /Users/steve/Desktop/thinkstock/rbrb_0556.jpg
2012-01-19 13:59:06.799 archiveDrop_cocoa[76758:10b] /Users/steve/Desktop/thinkstock/Manracefinish78464007.jpg
2012-01-19 13:59:08.319 archiveDrop_cocoa[76758:10b] /Users/steve/Desktop/thinkstock/ManLabtop86510699.jpg
2012-01-19 13:59:08.320 archiveDrop_cocoa[76758:10b] *** -[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1a75c0
2012-01-19 13:59:08.321 archiveDrop_cocoa[76758:10b] *** Canceling drag because exception 'NSInvalidArgumentException' (reason '*** -[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1a75c0') was raised during a dragging session
2012-01-19 13:59:10.726 archiveDrop_cocoa[76758:10b] /Users/steve/Desktop/thinkstock/LasVegassign78058995.jpg
2012-01-19 13:59:10.728 archiveDrop_cocoa[76758:10b] *** -[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1a9010
2012-01-19 13:59:10.729 archiveDrop_cocoa[76758:10b] *** Canceling drag because exception 'NSInvalidArgumentException' (reason '*** -[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1a9010') was raised during a dragging session
2012-01-19 13:59:13.342 archiveDrop_cocoa[76758:10b] /Users/steve/Desktop/thinkstock/kidscolor57448860.jpg
2012-01-19 13:59:15.014 archiveDrop_cocoa[76758:10b] /Users/steve/Desktop/thinkstock/IVDrip76801701.jpg
2012-01-19 13:59:18.263 archiveDrop_cocoa[76758:10b] /Users/steve/Desktop/thinkstock/stk26719pin.jpg
2012-01-19 13:59:23.414 archiveDrop_cocoa[76758:10b] /Users/steve/Desktop/thinkstock/WomanLabtop78634274.jpg
当你在上线调试器打破,你叫'componentsSeparatedByString:',什么是调试器说'thisImagePath'是? – user1118321
提示:在您尝试将componentsSeparatedByString应用于它之前,NSLog thisImagePath。 –
@HotLicks - 我有,我发布的这两条路径直接来自日志。 – PruitIgoe