[英]unrecognized selector sent to instance
我正在創建一個示例應用程序,其中我正在讀取數據庫並將用戶圖像和名稱顯示在tableview中。 但我得到以下例外
[UIApplication userListMutableArray]: unrecognized selector sent to instance 0x6816330
以下是我的代碼片段
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);
}
[appDelegate.userListMutableArray addObject:userData];
上面的行是異常,但我無法跟蹤問題。 :(
您的appDelegate變量指向UIApplication而不是其delegate屬性。 更改此作業...
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication];
至...
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
更改以下行
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication];
至
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.