iphone - [NSCFString 字符串值] : unrecognized selector sent to instance

标签 iphone objective-c

我正在使用这段代码来查询核心数据并返回键的值,我这样存储值:

 NSString *newName= @"test"; 
 [newShot setValue:newName forKey:@"shotNumber"]; 

我这样查询:

NSManagedObject *mo = [items objectAtIndex:0];  // assuming that array is not empty
  NSString *value = [[mo valueForKey:@"shotNumber"] stringValue];
  NSLog(@"Value : %@",value);

虽然这条消息让我崩溃了:

[NSCFString stringValue]: unrecognized selector sent to instance,

有谁知道那是从哪里来的?

最佳答案

newName (@"test") 已经是一个 NSString。无需调用 -stringValue 将其转换为字符串。

NSString *value = [mo valueForKey:@"shotNumber"];

关于iphone - [NSCFString 字符串值] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3823161/

相关文章:

ios - zPosition 和 subview 数组

ios - 用于设置颜色的iOS宏

ios - 更改照片编辑扩展的标题

iphone - 多次按下时声音重叠

ios - 当用户开始在 UISearchBar 中输入时应用程序崩溃

ios - 更新到 IOS 7 后应用程序崩溃

ios - secondsFromGMT 在设备和模拟器上返回不同的值

iPhone 应用程序试用期

iphone - 如何合并两个FBO?

ios - 了解 UITableView dequeueReusableCellWithIdentifier - 即使在第一次调用时也返回单元格