@interface Week : NSManagedObject {
}
@property (nonatomic, retain) NSNumber *weekID;
@property (nonatomic, retain) NSString *top;
@property (nonatomic, retain) NSString *summary1;
@property (nonatomic, retain) NSMutableArray *book;
@end
我是从服务器读取XML文件,并把瓦莱斯在entity.Since上面的书籍来阅读该周可多所以它被存储在MutableArray.I制造* book可在我的.xcdatamodel文件中转换。应坚持的NSMutableArray这是核心数据实体的财产
我的解析器看起来像这样解析并初始化上面周实体。
if ([currentTag isEqualToString:@"book"]) {
NSString *USGSWebLink = [currentElementValue1 stringByStandardizingPath] ;
[week.book addObject:USGSWebLink];
[week setBook:week.book];
NSError *error;
if (![self.managedObjectContext save:&error]) {
NSLog(@"%@", [error domain]);
}
因为我取从Coredata在的NSMutableArray“weekArray”以上的值和存储这是存储细**显示在**的UITableView。
我的程序在下面两个函数中崩溃,崩溃点在下面两个函数之间切换......奇怪!
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
**//sometimes program crashes at this point**
return [weekArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *object = (NSManagedObject *)[weekArray objectAtIndex:indexPath.row];
**// program crash at the above line.**
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [object valueForKey:@"top"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Set up the cell
return cell;
}
*请告诉我我在哪里做错了?难道是我存储的NSMutableArray 书在我的解析器或 NSManagedObject *object = (NSManagedObject *)[weekArray objectAtIndex:indexPath.row];
线 因为我的NSLog不会打印下面indexPath.row线的方式问题。
我取功能是:
- (void)fetchRecords {
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Week" inManagedObjectContext:appDelegate.managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity]; //NSLog(@"fetchRecords = %@",appDelegate.managedObjectContext);
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"weekID" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
NSError *error;
NSMutableArray *mutableFetchResults = [[[managedObjectContext executeFetchRequest:request error:&error] mutableCopy] autorelease] ;
if (!mutableFetchResults) {
}
if (mutableFetchResults == nil) {
NSLog(@"week fetch failed");
}
self.weekArray = mutableFetchResults; NSLog(@"weekArray = %@",weekArray);
[mutableFetchResults release];
[request release];
}
非常感谢“杰克”。删除“[mutableFetchResults发布]后,我的程序工作得很好;” 。我无法想象你自己。 – Ravi 2010-10-05 05:54:09