2011-11-11 59 views
3

我正在创建一个示例应用程序,其中我正在读取数据库并将用户图像和名称显示到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:用户数据]。

上面的行给出异常,但我无法跟踪问题。 :(

回答

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]; 
相关问题