托管对象崩溃 EXC_BAD_ACCESS
我有一个包含多个 NSString 的托管对象:
@interface Establishment : NSManagedObject
{
}
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * subtitle;
@property (nonatomic, retain) NSString * description;
我正在创建托管对象的实例并将字符串分配给标签,如下所示:
if ([establishmentData.name length]!= 0) {
estabName.text = establishmentData.name;
} else {
estabName.hidden = YES;
}
if ([establishmentData.subtitle length]!= 0) {
estabTitle.text = establishmentData.subtitle;
} else {
estabTitle.hidden = YES;
}
if ([establishmentData.description length]!= 0) {
estabDescription.text = establishmentData.description;
} else {
estabDescription.hidden = YES;
}
在这种情况下,名称有一个值,但副标题和描述为零。当它到达字幕时,它成功地失败了 if 并隐藏了文本字段,但是当它到达描述时,它崩溃了 EXC_BAD_ACCESS。我简单地尝试了 NSLogging setupData.description ,但它仍然崩溃
Backtrace 抛出了 62,000 行:
_PF_Handler_Public_GetProperty () 中的 62851 0x00d3dbbf
62852 0x00d3f2fb 在 -[NSManagedObject _descriptionValues] ()
62853 0x00d3d6b5 in -[NSManagedObject 描述]()
并以结尾
62854 0x00004b90 在 -[DataTable tableView:didSelectRowAtIndexPath:]
(自我=0x4d48df0,_cmd=0x6d59e3, 表视图=0x505d200, 索引路径 = 0x6111b00) 在 /Users/Com_23/Documents/projects/Est_list/Classes/DataTable.m:330
62855 0x0032e794 在 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
()
62856 0x00324d50 在 -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
()
__NSFireDelayedPerform () 中的 62857 0x000377f6
CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION 中的 62858 0x00f67fe3
()
__CFRunLoopDoTimer () 中的 62859 0x00f69594
__CFRunLoopRun()中的62860 0x00ec5cc9
CFRunLoopRunSpecific () 中的 62861 0x00ec5240
CFRunLoopRunInMode()中的62862 0x00ec5161
GSEventRunModal()中的62863 0x018bb268
GSEventRun()中的62864 0x018bb32d
UIApplicationMain () 中的 62865 0x002c742e
62866 0x00002958 在 main (argc=1, argv=0xbfffefe4) 处
/Users/Com_23/Documents/projects/Est_list/main.m:14
DataTable 是我的UITableViewController。有谁知道发生了什么事吗?在我看来一切都很好。
I have a managed object that has several NSStrings:
@interface Establishment : NSManagedObject
{
}
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * subtitle;
@property (nonatomic, retain) NSString * description;
I am creating an instance of the managed object and assigning the strings to labels, as such:
if ([establishmentData.name length]!= 0) {
estabName.text = establishmentData.name;
} else {
estabName.hidden = YES;
}
if ([establishmentData.subtitle length]!= 0) {
estabTitle.text = establishmentData.subtitle;
} else {
estabTitle.hidden = YES;
}
if ([establishmentData.description length]!= 0) {
estabDescription.text = establishmentData.description;
} else {
estabDescription.hidden = YES;
}
In this case, name has a value, but subtitle and description are nil. When it gets to subtitle, it successfully fails the if and hides the text field, but when it gets to description it crashes EXC_BAD_ACCESS. I tried simply NSLogging establishmentData.description and it still crashes
Backtrace throws out 62,000 lines of this:
62851 0x00d3dbbf in _PF_Handler_Public_GetProperty ()
62852 0x00d3f2fb in -[NSManagedObject _descriptionValues] ()
62853 0x00d3d6b5 in -[NSManagedObject description] ()
and ends with
62854 0x00004b90 in -[DataTable tableView:didSelectRowAtIndexPath:]
(self=0x4d48df0, _cmd=0x6d59e3,
tableView=0x505d200,
indexPath=0x6111b00) at
/Users/Com_23/Documents/projects/Est_list/Classes/DataTable.m:33062855 0x0032e794 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
()
62856 0x00324d50 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
()
62857 0x000377f6 in __NSFireDelayedPerform ()
62858 0x00f67fe3 in CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
()
62859 0x00f69594 in __CFRunLoopDoTimer ()
62860 0x00ec5cc9 in __CFRunLoopRun ()
62861 0x00ec5240 in CFRunLoopRunSpecific ()
62862 0x00ec5161 in CFRunLoopRunInMode ()
62863 0x018bb268 in GSEventRunModal ()
62864 0x018bb32d in GSEventRun ()
62865 0x002c742e in UIApplicationMain ()
62866 0x00002958 in main (argc=1, argv=0xbfffefe4) at
/Users/Com_23/Documents/projects/Est_list/main.m:14
DataTable being my UITableViewController. Does anyone have any idea what is going on? Everything looks fine to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能将属性命名为“description”。请参阅:
访问 NSManagedObject 中的属性会导致内存峰值和崩溃
参考(Apple 文档):
http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Reference/CoreDataFramework/Classes/NSPropertyDescription_Class/NSPropertyDescription.html
You cannot give a property the name “description”. See:
Accessing a property in NSManagedObject causes memory spike and crash
Reference (Apple Documentation):
http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Reference/CoreDataFramework/Classes/NSPropertyDescription_Class/NSPropertyDescription.html