[英]Xcode FMDB to UIWebview
我想将FMDB内容显示到UIWebview中。
这是我的代码。 可以帮助我如何在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];
}
您应该创建一个NSMutableString
并将数据附加到该字符串,然后将该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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.