2012-01-24 7 views
0

내 프로젝트에 SITiteview에 Sqlite3를 연결하면 코드가 잘되었습니다. 그러나 데이터 대신 시뮬레이터에서 테이블을 열면 <db: 0x8a35e20>과 같은 내용이 표시됩니다. 아무도 내가 잘못한 것을 알려 줄 수 있습니까?UITabel에서 SQlite3에 연결된 오류

아래 표 내 코드를 찾아주세요 : 당신은 직접의 tableview의 label.You에 DB 객체를 설정하는

#import "table1.h" 
#import "db.h" 

@implementation table1 
@synthesize tableOne; 

#pragma mark - View lifecycle 
- (void)viewDidLoad 
{ 

    [email protected]"nobel10.db"; 

    NSArray *documentPaths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString * documentDir = [documentPaths objectAtIndex:0]; 
    databasePath=[documentDir stringByAppendingPathComponent:databaseName]; 
    [self checkAndCreateDatabase]; 
    [self readDataFromDatabase]; 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 


#pragma mark - TableView Data Source methods 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return [tableOne count]; } 

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier: 
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls) 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *cell= nil; 
    cell = [tableView dequeueReusableCellWithIdentifier:@"mycell"]; 
    if (cell == nil) { 
     cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mycell"];} 
    cell.textLabel.text =[NSString stringWithFormat:@"%@" ,[tableOne objectAtIndex:indexPath.row]]; 
    return cell;} 
-(void)checkAndCreateDatabase{ 
    BOOL success; 
    NSFileManager *fileManager=[NSFileManager defaultManager]; 
    success=[fileManager fileExistsAtPath:databasePath]; 
    if(success) 
     return; 

    NSString *databasePathFromApp = [[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:databaseName]; 
    [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; 
    [fileManager release]; 
} 
-(void)readDataFromDatabase{ 
    sqlite3 *database; 
    tableOne=[[NSMutableArray alloc]init]; 
    if(sqlite3_open([databasePath UTF8String], &database)== SQLITE_OK){ 
    const char *sqlStatement = "SELECT * FROM gender"; 
     sqlite3_stmt *compiledStatement; 
     if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL)==SQLITE_OK){ 
      while (sqlite3_step(compiledStatement)==SQLITE_ROW) { 
       NSString *stringName=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]; 

       db *info =[[db alloc]initWithName:stringName]; 
       [tableOne addObject:info]; 
       [info release]; 
      } 

     } 
     sqlite3_finalize(compiledStatement); 
    } 
    sqlite3_close(database); 
} 
- (void)dealloc 
{ 

    [tableOne release]; 
    [super dealloc]; 
} 

@end 
+0

일부 코드를 표시하십시오. – Sarah

+0

코드를 찾으십시오. – user1118664

+0

[tableOne addObject : info] 뒤에 tableOne을 유지하십시오. – Sarah

답변

0

하는

을 다음과 같이 라벨에 DB 객체의 인스턴스 변수 값을 설정해야 할 수도 있습니다를
cell.textLabel.text =[NSString stringWithFormat:@"%@" ,[(db*)[tableOne objectAtIndex:indexPath.row]name]]; 
+0

안녕하세요 Monish ..이 코드를 따르는 경우 오류가 // Thread1 : 프로그램에서받은 신호 "EXC_BAD_ACCESS"로 표시됩니다. – user1118664

관련 문제