使用FMDB将数据从sqlite显示到标签 [英] display data from sqlite to label using FMDB

查看:115
本文介绍了使用FMDB将数据从sqlite显示到标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用FMDB将数据从SQLite显示到标签,如下所示:

How to display data from SQLite to label using FMDB like this:

我想显示此格式的输出,供用户查看。没有互动。仅显示选择查询。

I would like to display whatever the output is in this format for the user to see. No Interaction. Only display for the select query.

推荐答案

如果要添加 UILabel 对象,只需遍历结果集,向视图添加标签即可。类似于:

If you want to add UILabel objects, just iterate through your result set, adding labels to your view. Something like:

NSInteger rowNum = 0;
NSArray *columnWidths = @[@(50), @(120), @(75), @(75)];
CGFloat rowHeight = 24.0;

FMResultSet *rs = [db executeQuery:sql];

while ([rs next])
{
    CGFloat x = 0.0;
    NSInteger colNum = 0;
    for (NSNumber *columnWidth in columnWidths)
    {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x,
                                                                    rowHeight * rowNum, 
                                                                    [columnWidth floatValue], 
                                                                    rowHeight)];
        label.textAlignment = NSTextAlignmentCenter;
        label.layer.borderColor = [UIColor blackColor].CGColor;
        label.layer.borderWidth = 1.0;
        label.text = rs[colNum++];
        [self.view addSubview:label];
        x += [columnWidth floatValue];
    }
    rowNum++;
}

[rs close];

我刚输入,所以我确定那里有拼写错误,但希望它足够了让你知道它的外观。如果屏幕上有太多行,您可以在视图中添加一个滚动视图,然后将标签作为子视图添加到该视图中。

I just typed that in, so I'm sure there are typos in there, but hopefully it's enough to give you an idea of what it could look like. If there are too many rows to fit on a screen, you would add a scrollview to your view, and then add the labels as a subview to that.

我也认为tableview是一个很棒的方法。或者动态构建一个在 UIWebView 中显示的HTML字符串。这里有很多选择。这取决于你的最终目标是什么,数据的性质,你想要的用户互动类型。

I also think the tableview is a wonderful approach. Or dynamically built a HTML string that you show in a UIWebView. Tons of options here. It depends a little upon what your ultimate goal is here, the nature of the data, what sort of user interaction you want.

这篇关于使用FMDB将数据从sqlite显示到标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆