当调用下面的函数时,我得到 EXC_BAD_ACCESS 崩溃。看起来 FMDB 在解释 subject_id NSInteger 时遇到了问题,因为它在 WHERE 子句中遇到了这个 subject_id 列时,它通过了两个 NStrings 和炸弹。
- (void) saveAllData {
if(isDirty) {
DrillDownAppAppDelegate *appDelegate = (DrillDownAppAppDelegate *)[[UIApplication sharedApplication] delegate];
FMDatabase *database = [FMDatabase databaseWithPath:appDelegate.getDBPath];
if ([database open]) {
[database executeUpdate:@"update Subject Set subject = ?, category = ? where subject_id = ?",
self.title, self.category_title, self.subject_id];
[database close];
}
isDirty = NO;
}
//Reclaim all memory here.
[title release];
title = nil;
[category_title release];
category_title = nil;
}
这个问题与我在另一篇关于 FMDB 插入问题的帖子中遇到的问题相同,这归结为我的 subject_id 成员有问题。我相信我在标题中使用了错误的声明。这里是:
//
// Subject.h
// DrillDownApp
#import <UIKit/UIKit.h>
@interface Subject : NSObject {
NSInteger subject_id;
NSString *category_title;
NSString *title;
// NSMutableArray *quotes;
BOOL isDirty;
// BOOL isDetailViewHydrated;
}
- (id) initWithPrimaryKey:(NSInteger)pk;
@property (nonatomic, readwrite) BOOL isDirty;
//@property (nonatomic, readwrite) BOOL isDetailViewHydrated;
- (void) addSubject;
- (NSInteger)getNextSubjectId;
@property (nonatomic, assign) NSInteger subject_id;
@property (nonatomic, copy) NSString * title;
@property (nonatomic, copy) NSString * category_title;
//@property (nonatomic, retain) NSMutableArray *quotes;
//- (void) saveAllData;
@end
(注意:当我弄清楚其余部分时,我主要编辑了这个。)