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

时间:2012-01-05 13:23:42

标签: iphone objective-c xcode cocoa

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

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

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

这会返回一个无法识别的选择器。我在我的项目的其他区域使用这行代码,它工作正常。但不是这个。

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

有什么想法吗?

3 个答案:

答案 0 :(得分:2)

我也有同样的问题,而我的字符串有这么多白色字符,新行字符所以我什么都做不了,但最后我得到了解决方案如下:

 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

这样我现在得到了一个完美的数组,它在我们的控制之下

答案 1 :(得分:0)

将其设为以下,假设variants为NSString

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

答案 2 :(得分:0)

您没有向我们提供完整的错误消息,但我的打赌:您过度释放任何一个词或变体,因此该消息由另一个对象接收,该对象没有选择器中提到的方法。试试NSZombieEnbled。你会在StackOverflow上找到足够的关于它的帖子。

修改
您发布的错误符合我的假设。唯一的另一种解释是:variants是NSArray。