托管对象崩溃 EXC_BAD_ACCESS

发布于 2024-11-02 09:49:18 字数 2307 浏览 1 评论 0原文

我有一个包含多个 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:330

62855 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不离久伴 2024-11-09 09:49:18

您不能将属性命名为“description”。请参阅:

访问 NSManagedObject 中的属性会导致内存峰值和崩溃

参考(Apple 文档):

http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Reference/CoreDataFramework/Classes/NSPropertyDescription_Class/NSPropertyDescription.html

属性描述单个值
在由 Core 管理的对象内
数据框架。有不同的
属性类型,每种属性由
一个封装了的子类
具体属性行为——参见
NS属性描述,
NSRelationshipDescription,以及
NSFetchedPropertyDescription。

请注意,属性名称不能是
与任何无参数方法相同
NSObject 或 NSManagedObject 的名称。
例如,您不能给出
属性名称“描述”
。那里
NSObject 上有数百个方法
可能会与财产发生冲突
名字——这个列表可以增长,而无需
来自框架或其他的警告
图书馆。你应该避免非常
一般词(例如“字体”,以及
“颜色”)以及单词或短语
与 Cocoa 范式重叠(例如
“isEditing”和“objectSpecifier”)

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

A property describes a single value
within an object managed by the Core
Data Framework. There are different
types of property, each represented by
a subclass which encapsulates the
specific property behavior—see
NSAttributeDescription,
NSRelationshipDescription, and
NSFetchedPropertyDescription.

Note that a property name cannot be
the same as any no-parameter method
name of NSObject or NSManagedObject.
For example, you cannot give a
property the name "description"
. There
are hundreds of methods on NSObject
which may conflict with property
names—and this list can grow without
warning from frameworks or other
libraries. You should avoid very
general words (like "font”, and
“color”) and words or phrases which
overlap with Cocoa paradigms (such as
“isEditing” and “objectSpecifier”)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文