我正在用兩個簡單的視圖創建一個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