Iphone 从NSManagedObject获取字符串
当我尝试从NSManagedObject获取字符串值时,我得到Iphone 从NSManagedObject获取字符串,iphone,ios,objective-c,core-data,nsmanagedobject,Iphone,Ios,Objective C,Core Data,Nsmanagedobject,当我尝试从NSManagedObject获取字符串值时,我得到 <Entity: 0x1e043140> (entity: Entity; id: 0x1e041c30 <x-coredata://8F48C331-B879-47B4-B257-4802A13ED12C/Entity/p4> ; data: { number = "<UITextField: 0x1d8b7cc0; frame = (159 183; 161 30); text = 'test';
<Entity: 0x1e043140> (entity: Entity; id: 0x1e041c30 <x-coredata://8F48C331-B879-47B4-B257-4802A13ED12C/Entity/p4> ; data: {
number = "<UITextField: 0x1d8b7cc0; frame = (159 183; 161 30); text = 'test'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1d8b3c10>; layer = <CALayer: 0x1d892a30>> : ";
})
好的,nsmanaged对象是this,并将uitableview单元格设置为其字符串
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[object valueForKey:@"number"] description];
它之所以显示它的功能,是因为,正如你所看到的,我得到了它的描述。我找不到返回文本值的属性,所以有人知道如何返回吗?谢谢。你应该写:
Entity *entity = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *rowValue = entity.text;
编辑:
好,然后尝试
object.number.text代码>我假设在托管对象中存储值时已经发生错误。也许你会做类似的事情
[myObject setValue:[aTextField description] forKey:@"number"]
不是存储文本字段的文本内容,而是:
[myObject setValue:[aTextField text] forKey:@"number"]
更新:在注释中写入时,托管对象值存储为
NSString *string = [NSString stringWithFormat:@"%@ : %@", self.numtext, self.comtext];
[newManagedObject setValue:string forKey:@"number"];
但是UITextField
本身的%@
格式扩展为文本字段描述,而不是文本内容。因此,字符串
看起来就像
"<UITextField: 0x1d8b7cc0; frame = (159 183; 161 30); text = 'test'; .... "
请注意,在测试时,您必须删除旧数据库,以清除已经存在的错误条目。您必须获取实际的UITextField
,并使用其text
属性。我不知道。这里几乎没有什么信息。@H2CO3我编辑了它。我说的有帮助吗?是的,谢谢,但我相信李维已经得到了答案。entity.textField.text
或类似的东西怎么样?entity没有文本属性我尝试了对象.number
(number已经是字符串)但仍然不起作用我像这样添加它`NSString*string=[NSString stringWithFormat:@“%@:%@”、self.numtext、self.comtext];[newManagedObject设置值:字符串forKey:@“number”];'如果self.numtext
,self.comtext
是UITextField
变量,那么您必须使用[NSString stringWithFormat:@“%@:%@”,self.numtext.text,self.comtext.text]
。这确实对我有所帮助,我只是注意到我在那里做错了什么,但是它仍然不会显示字符串。那么现在object
的值是多少?和以前一样,但它保存文本,而不是null
NSString *str = managedObject.objectID.URIRepresentation.absoluteString
NSString *string = [NSString stringWithFormat:@"%@ : %@", self.numtext.text, self.comtext.text];
[newManagedObject setValue:string forKey:@"number"];
NSString *str = managedObject.objectID.URIRepresentation.absoluteString