2014-04-08 2 views
0

FMDB 내용을 UIWebview에 표시하려고합니다.Xcode FMDB to UIWebview

이것은 내 코드입니다. 어떤 사람은 당신이 NSMutableString을 만들고 해당 문자열과 부하에 데이터를 추가해야 내가 모든

루프 표시 할 내가있는 UIWebView

에 표시 할 수있는 방법으로 도와 당신에게

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    myContent = [[NSMutableArray alloc] init]; 

    NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"sqlite"]; 

    FMDatabase *db = [[FMDatabase alloc] initWithPath:path]; 

    [db open]; 

    FMResultSet *fResult= [db executeQuery:@"SELECT * FROM contents"]; 


    while([fResult next]) 
    { 
     edata = [fResult stringForColumn:@"title"]; 
     [myContent addObject:edata]; 
    } 

    [fResult next]; 
    NSString *title = [fResult stringForColumn:@"title"]; 


    [myWeb loadHTMLString:[NSString stringWithFormat:@"%@%@%@" ,@"<html><body>",title,@"</body></html>"] baseURL:nil]; 

} 

답변

0

감사 할 수 html 문자열은 UIWebView입니다.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    myContent = [[NSMutableArray alloc] init]; 

    NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"sqlite"]; 

    FMDatabase *db = [[FMDatabase alloc] initWithPath:path]; 

    [db open]; 

    FMResultSet *fResult= [db executeQuery:@"SELECT * FROM contents"]; 

    NSMutableString *str = [NSMutableString stringWithString:@"<html><body>"]; 

    while([fResult next]) 
    { 
     [str stringByAppendingString:[NSString stringWithFormat:@"<p>%@</p>",[fResult stringForColumn:@"title"]]]; 
     edata = [fResult stringForColumn:@"title"]; 
     [myContent addObject:edata]; 
    } 

    [str stringByAppendingString:@"</body></html>"]; 

    [fResult next]; 
    NSString *title = [fResult stringForColumn:@"title"]; 


    [myWeb loadHTMLString:str baseURL:nil]; 

} 
+0

작동하지, 내가 나에게 –

+0

도와주세요 다시 내 코드를 게시 할 예정이 같은 해결 : STR = [STR의 stringByAppendingString : [있는 NSString stringWithFormat : "

@

%"@ [fResult stringForColumn : @ "제목" ]]]; –