首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode FMDB到UIWebview

Xcode FMDB到UIWebview
EN

Stack Overflow用户
提问于 2014-04-08 11:32:11
回答 1查看 80关注 0票数 0

我想将FMDB内容显示到UIWebview中。

这是我的密码。有人能帮我如何在UIWebview中显示

我想显示所有的循环

谢谢

代码语言:javascript
复制
- (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];

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-08 11:46:32

您应该创建一个NSMutableString,并将数据追加到该字符串中,并在UIWebView中加载该html字符串,如下所示。

代码语言:javascript
复制
- (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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22935706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档