iphone - NSArray compontentsSeperatedByString 返回无法识别的选择器

标签 iphone objective-c xcode cocoa

我有一个包含三个单词的字符串,由管道 ( | ) 分隔 我想将它们分成三个单独的字符串

NSArray *bits = [word.variants componentsSeparatedByString: @"|"];

NSLog(@"BITS: %@", bits);

这将返回一个无法识别的选择器。我在项目的其他区域使用了这行代码,并且运行良好。但不是这个。

-[__NSArrayI componentsSeparatedByString:]: unrecognized selector sent to instance 0x6dbfa80

有什么想法吗?

最佳答案

我也有同样的问题,而我的字符串有这么多白色字符、换行符,所以我无能为力,但最后我得到了如下解决方案:

 NSString *artwork = [currentURL valueForKey:@"artwork_large"]; 
     //i got the string artwork ,which is fetch from json.

[smg addObject:artwork];   
     // add this string to 0th index of an array name:smg


NSSet *setObj1 = [NSSet setWithArray:smg];
      //make the nsset for my array (named :smg)

NSString *pictureName = [[setObj1 allObjects] componentsJoinedByString:@","];
      //make the string from all the sets joined by ","


picArray = [pictureName componentsSeparatedByString:@","];
      //now its time for normal operation means makes the array (name: picArray) from string by componenet separatedbystring method

这样我现在就得到了我们可以控制的完美数组

关于iphone - NSArray compontentsSeperatedByString 返回无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8743246/

相关文章:

ios - iPhone OS Utility App - Flipside View 和 Main View 通信

ios - iPhone X - 我们应该如何处理表格部分标题上方的空间?它通过内容显示

iphone - 核心数据: Fetch via specific property (join relationship)

iphone - Box2d Loop Shape/在 Cocos2D 中创建静态地面形状

objective-c - 如何在 drawRect 中为 NSTextField 或 NSTextVew 实现自定义聚焦环

ios - 在 Xcode 4 中设置事件构建配置的位置

iphone - UIImageView 仅在我调用 initWithImage 时显示

objective-c - 反射 : Should set property or directly set value? 时(Objective-C)

xcode - NSPopupButton 的值为零

ios - 自引用快速关闭