我想将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];
}发布于 2014-04-08 11:46:32
您应该创建一个NSMutableString,并将数据追加到该字符串中,并在UIWebView中加载该html字符串,如下所示。
- (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];
}https://stackoverflow.com/questions/22935706
复制相似问题