2011-11-11 3 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 : userData에]

위의 행은 예외가 있지만 문제를 추적 할 수 없습니다. :(

답변

8

AppDelegate에 변수는 위임 속성을 UIApplication을 가리키고 있지 않습니다.이 과제를 변경 ...

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

에 ...

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

고맙습니다. 그것은 내 문제를 해결했다. –

1

변경 다음 줄

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

to

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; 
관련 문제