核心数据在看似正常的 NSString 字段上崩溃
我有另一个奇怪的错误,我无法弄清楚。
我尝试使用下面的代码创建一个 tableviewcell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TableViewCellController *cell = (TableViewCellController *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
cell = [_cell autorelease];
_cell = nil;
}
// Configure the cell...
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
Article *article = (Article *)[articles objectAtIndex: storyIndex];
cell.titleLabel.text = article.title;
cell.siteLabel.text = article.site.name;
cell.summaryLabel.text = article.description;
[article release];
return cell;
}
问题是我可以使用任何值填充标签,但描述值除外。一旦我这样做,我就会遇到以下崩溃:
2010-12-22 16:07:13.165 iDoms[24086:207] CoreData:注释:从数据库中完成故障:0x8b16dd0 程序收到信号:“EXC_BAD_ACCESS”。 警告:无法恢复先前选择的帧。 数据格式化程序暂时不可用,将在“继续”后重试。 (此时调用 dlopen 不安全。)
堆栈上有 62820 个行项目。 我不知道从哪里开始解决这个问题。我已经习惯了 Java,而 Objective-C 到目前为止对于一些奇怪的 bug 来说真是一场噩梦。
Article 类如下所示:
// Article.h
#import <CoreData/CoreData.h>
@class Site;
@interface Article : NSManagedObject
{
}
@property (nonatomic, retain) NSNumber * id;
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSNumber * read;
@property (nonatomic, retain) NSString * link;
@property (nonatomic, retain) NSDate * pubDate;
@property (nonatomic, retain) NSString * description;
@property (nonatomic, retain) NSDate * lastUpdate;
@property (nonatomic, retain) Site * site;
@end
数据库
// Article.m
#import "Article.h"
@implementation Article
@dynamic id;
@dynamic title;
@dynamic read;
@dynamic link;
@dynamic pubDate;
@dynamic description;
@dynamic lastUpdate;
@dynamic site;
@end
包含数据,特定字段只是字符串“Test1”。 一如既往,我们非常感谢任何帮助!
I have another strange bug which I cannot figure out.
I try to create a tableviewcell with the code below:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TableViewCellController *cell = (TableViewCellController *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
cell = [_cell autorelease];
_cell = nil;
}
// Configure the cell...
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
Article *article = (Article *)[articles objectAtIndex: storyIndex];
cell.titleLabel.text = article.title;
cell.siteLabel.text = article.site.name;
cell.summaryLabel.text = article.description;
[article release];
return cell;
}
The problem is that I can populate the labels with any value, except with the description value. As soon as I do that I get a the following crash:
2010-12-22 16:07:13.165 iDoms[24086:207] CoreData: annotation: fault fulfilled from database for : 0x8b16dd0
Program received signal: “EXC_BAD_ACCESS”.
warning: Unable to restore previously selected frame.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.)
with 62820 line items on the stack.
I have no idea where to start figuring this out. I am used to Java, and Objective-C has been a real nightmare so-far regarding little strange bugs.
The Article class looks like this:
// Article.h
#import <CoreData/CoreData.h>
@class Site;
@interface Article : NSManagedObject
{
}
@property (nonatomic, retain) NSNumber * id;
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSNumber * read;
@property (nonatomic, retain) NSString * link;
@property (nonatomic, retain) NSDate * pubDate;
@property (nonatomic, retain) NSString * description;
@property (nonatomic, retain) NSDate * lastUpdate;
@property (nonatomic, retain) Site * site;
@end
and
// Article.m
#import "Article.h"
@implementation Article
@dynamic id;
@dynamic title;
@dynamic read;
@dynamic link;
@dynamic pubDate;
@dynamic description;
@dynamic lastUpdate;
@dynamic site;
@end
The database contains data, and the particular field just the string "Test1".
Any help is really appreciated as always!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
堆栈跟踪的大小使我相信您在某个地方有一个无限递归循环。
我将查看正在创建的自定义 UITableViewCell 的构造,即summaryLabel 控件以及它如何连接到单元格中。
我还要确保 posts 数组的属性被保留。
The size of the stack trace leads me to believe that you've got an infinite recursion loop going somewhere.
I would look at the construction of the custom UITableViewCell that is getting created, namely the summaryLabel control and how it is wired into the cell.
I would also make sure that the articles array is property retained.
我不知道这是否与您当前的问题有关,但您不想进行[文章发布];在您的 cellForRowAtIndexPath 方法中,因为 objectAtIndex 不会为您提供需要释放的引用。
I do not know if this is related to your current issue, but you do not want to do the [article release]; in your cellForRowAtIndexPath method, as objectAtIndex does not give you a reference that needs to be released.