我正在用两个简单的视图创建一个SQLite应用程序。我在SQLAppDelegate两个数组:Objective-C appDelegate数组
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
self.modelArray = tempArray;
self.detailArray = tempArray;
[tempArray release];
所以现在我实现文件中我填充“modelArray”用一个SQLite表中的内容,并在第一视图中显示此:
+ (void) getInitialDataToDisplay:(NSString *)dbPath {
SQLAppDelegate *appDelegate = (SQLAppDelegate *)[[UIApplication sharedApplication] delegate];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
const char *sql = "select rowid as ID, ManufacturerMake as modelName from sqlitedb group by modelName";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
Model *modelObj = [[Model alloc] initWithPrimaryKey:primaryKey];
modelObj.modelName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
[appDelegate.modelArray addObject:modelObj];
[modelObj release];
}
}
}
问题是模型阵列正在114行正确填充,但如果我做了一个计数detailArray上述while语句后,这也是返回114?即使我没有触及上述代码中的detailArray?
谢谢,那会是原因。 – StuR 2011-05-29 21:31:07