2011-11-11 13 views
3

私はデータベースを読み込み、ユーザのイメージと名前をtableviewに表示している1つのサンプルアプリケーションを作成しています。 しかし、私は[appDelegate.userListMutableArrayのaddObject:のuserData]私のコードスニペットインスタンスに送信された認識できないセレクタ

AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication]; 

if(sqlite3_open([dbPath UTF8String], &database)==SQLITE_OK) 
{ 
    const char *sql = "select NAME,IMAGE from user"; 
    sqlite3_stmt *selectstmt; 

    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL)==SQLITE_OK) 
    { 
     while (sqlite3_step(selectstmt) == SQLITE_ROW) { 

      UserData *userData = [[UserData alloc] init]; 
      userData.userName = [NSString stringWithUTF8String:(char*)sqlite3_column_text(selectstmt, 0)]; 
      NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selectstmt, 1) length:sqlite3_column_bytes(selectstmt, 1)]; 
      if(data == nil) 
       NSLog(@"image not found"); 
      userData.userImage = [UIImage imageWithData:data]; 


      **[appDelegate.userListMutableArray addObject:userData];** 
     } 

    } 
} 
else 
{ 
    sqlite3_close(database); 
} 

で、次の次の例外

[UIApplication userListMutableArray]: unrecognized selector sent to instance 0x6816330 

を取得しています。

上記の行は例外ですが、私は問題を追跡できません。 :(

答えて

8

あなたappDelegate変数は、そのデリゲートのプロパティをのUIApplicationをポイントしていません。この割り当てを変更...

AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication]; 

に...

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
+0

thanxそれは私の問題を解決しました。 –

1

変更するには、次の行

AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication]; 

~

クイック返信用の
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];