我正在讀取數據庫中的文件路徑&將它們添加到我的委託中定義的數組(& alloc'd/initialised)之前將它們轉換爲NSURL。問題在於urlArray沒有被正確填充。將數據存儲在代理中定義的數組中
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
const char *sql = "select coffeeID, coffeeName from coffee";
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);
Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:primaryKey];
coffeeObj.coffeeName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
coffeeObj.isDirty = NO;
NSString *path = coffeeObj.coffeeName;
NSURL *url = [[NSURL alloc] initFileURLWithPath:soundPath];
[appDelegate.urlArray addObject:url];
[appDelegate.coffeeArray addObject:coffeeObj];
[coffeeObj release];
}
}
}
我嘗試訪問urlArray發現它是空的
SQLAppDelegate *appDelegate = (SQLAppDelegate *)[[UIApplication sharedApplication] delegate];
NSURL *url0 = [appDelegate.urlArray objectAtIndex:0];
的網址是否正確創建,這只是他們似乎並不像預期的那樣加入到urlArray。有任何想法嗎?在此先感謝:)
我不認爲你明白代表應該如何工作。你不應該直接調用代理屬性的方法,而是發送消息讓他們按照自己的意願去做。這可能不是問題,但你打破了標準的可可慣例。 – 2012-02-08 19:48:53
好的,我一直在關注在Sqlite數據庫實現中找到的[tutorial](http://www.iphonesdkarticles.com/2008/10/sqlite-tutorial-selecting-data.html)。這就是我發現代碼的地方。感謝您的提示 – Octave1 2012-02-08 21:09:01
什麼是聲音路徑,你在哪裏定義它?是否有可能你想從路徑創建NSUrl而不是聲音路徑? – AndreasZ 2012-02-08 22:38:19