Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unrecognized selector sent to instance

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. :(

like image 243
akrant_iOSDeveloper Avatar asked Aug 30 '26 20:08

akrant_iOSDeveloper


1 Answers

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];
like image 149
mmccomb Avatar answered Sep 02 '26 11:09

mmccomb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!