2013-08-08 2 views
-5

내 다음보기에는 4 개의 필드가 있으며 이름이 테이블에서 선택되면 모든 세부 정보를 표시하려고합니다. 로 데이터베이스를 만들기위한행 선택시 다음보기의 데이터 세부 정보 검색

코드 :

-(IBAction) saveData 
    { 
     sqlite3_stmt *statement; 
     const char *dbpath = [databasePath UTF8String]; 
     if (sqlite3_open(dbpath, &Information) == SQLITE_OK) 
     { 
      NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO CONTACTS (name,address, phone,imageUrl) VALUES (\"%@\", \"%@\", \"%@\",\"%@\")", name.text,address.text,phone.text,imageUrl.text]; 
       const char *insert_stmt = [insertSQL UTF8String]; 
       sqlite3_prepare_v2(Information, insert_stmt, -1, &statement, NULL); 

       if (sqlite3_step(statement) == SQLITE_DONE) 
       { 
        status.text = @"Contact added"; 

        name.text = @"";    

        address.text = @""; 

        phone.text = @""; i 
        [email protected]""; 

       } else 


       { 
        status.text = @"Failed to add contact"; 
       } 
       sqlite3_finalize(statement); 


       sqlite3_close(Information); 
     } 
    } 

나는 IOS 개발에 새로운 오전, 그래서 전술 한 바와 같이 내 상세보기에서 데이터를 표시하는 방법을 제안 해주십시오. 감사합니다

+4

을 시도 할 수 있습니다? – borrrden

답변

0

디스플레이 데이터를 들면 당신은 지진이 질문에 충돌이 되었습니까

-(void)displayData 
{ 
    const char *dbpath = [databasePath UTF8String]; 

    if(sqlite3_open(dbPath, &Information)==SQLITE_OK) 
    { 
     const char *qry=[@"select * from CONTACTS" UTF8String]; 
     sqlite3_stmt *statement; 

     if (sqlite3_prepare_v2(dtdb, qry, -1, &statement, NULL)==SQLITE_OK) 
     { 
      while (sqlite3_step(statement)==SQLITE_ROW) 
      { 
       NSString *name=[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 0)]; 
       NSString *address=[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 1)]; 
       NSString *phone=[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 2)]; 
       NSString *imageUrl=[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 3)]; 

       NSLog(@"name:%@ , address :%@ , phone:%@ , imageurl:%@",name,address,phone,imageUrl); 
      } 
     } 

    } 


} 
+0

고마워, 코드가 작동하지만 행을 선택하면 어떻게이 메서드를 호출 할 수 있습니까 ?? –

+0

if (sqlite3_prepare_v2 (dtdb, qry, -1, & statement, NULL) == SQLITE_OK) 여기 코드가 눌려져 있음 –

+0

'- (void) tableView : (UITableView *) tableView didSelectRowAtIndexPath : (NSIndexPath *) indexPath' 방법 어떤 오류가 발생합니까 ?? –

관련 문제