unrecognized selector sent to instance

ぐ巨炮叔叔 提交于 2019-12-10 21:28:13

问题


I am creating one sample application in which i am reading database and displaying user image and name into tableview. but i am getting following exception

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

following is my code snippet

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];

above line is giving exception but i am not able to track problem. :(


回答1:


Your appDelegate variable is pointing to the UIApplication and not its delegate property. Change this assignment...

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

to...

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



回答2:


Change the following line

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

to

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


来源:https://stackoverflow.com/questions/8093423/unrecognized-selector-sent-to-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!