display data from sqlite to label using FMDB


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

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/Qhwj3.gif" data-original="https://i.stack.imgur.com/Qhwj3.gif" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

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.


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.

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.


You can accomplish the above by using a <em>UITableView</em> and <strong>custom</strong> <em>UITableViewCells</em>.

And you can maintain an array which will act as a data source to your view controller.

Considering that you want to have the same layout as you have shared (which has four labels per row), you will be fetching the data from a database.

Since, the data fetched from a database may keep on increasing, UITableView is your best bet when displaying long list of data as memory management and cell creation is handled automatically.

If you plan to have only labels then things can get <em>tricky</em> for you. Because if the number of rows that you fetch using select query is too much then you will end up creating a lot of views which will cause memory issues.

And, if you don't want you user to interact with any of the rows, then implement the following method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; }

Here is a link for creating custom cells:

<a href="http://www.appcoda.com/customize-table-view-cells-for-uitableview/" rel="nofollow">http://www.appcoda.com/customize-table-view-cells-for-uitableview/</a>

Here is a link for using table view:

<a href="http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/" rel="nofollow">http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/</a>

Good Luck!!


  • UIScrollView not updating and displaying properly
  • How to dynamically set the colour of a 'div' element to match that of the colour picked on
  • Change color to a title of a button in Swift [duplicate]
  • Google Maps OverlayView: make only SVG clickable
  • Google Maps OverlayView: make only SVG clickable
  • passing data between view controllers programmatically Swift
  • Xamarin UI Test. Take control's background color ios
  • How to implement delete functionality for images in different positions in iCarousel iphone
  • How can I redirect from a grid view when a row is clicked
  • How to create a customized rounded UiView and UIButton like MobilePASS?
  • Why don't added sublayers show up in screenshot?
  • Highcharts not rendering in internet explorer
  • LLVM 3.0 compiler error: cast of C pointer type to Objective-C pointer type 'id' requires
  • C#: How To Crosshatch A Bar In An ASP.Net Bar Chart
  • 'Terminating app due to uncaught exception'.. it couldn't find MainWindow, which no l
  • Merge two imageViews into one and save iOS swift
  • String not fitting in label which is in a subview for swift
  • Enabling domxml in php
  • How to Update UILabel from Another ViewController
  • UITableViewCell change selectedBackgroundView alpha?
  • Change of MySQL database location not working
  • Solid Shadow in All Directions
  • Changing MySQL charset to UTF8 on linux so it will work with JDBC
  • Bind data to Gridview instance inside ListView ItemDataBound
  • Xamarin forms toggle button default color on IOS
  • UIButton Borders Function Only Gives Back White Borders
  • Install PHP intl extension on MacOS
  • Bad request using file_get_contents for PUT request in PHP
  • Optimizing database types to compact database (SQLite)
  • TFS: Get latest causes slow project reloading
  • SSO with signing and signature validation doesn't work
  • MySQL WHERE-condition in procedure ignored
  • Running a C# exe file
  • Deserializing XML into class C#
  • Web-crawler for facebook in python
  • trying to dynamically update Highchart column chart but series undefined
  • costura.fody for a dll that references another dll
  • Reading document lines to the user (python)
  • java string with new operator and a literal
  • How to push additional view controllers onto NavigationController but keep the TabBar?