How to tell if a sqlite table view is empty? - ios

I have a working RSS feed reader using SQLite 3 for the iPhone that I have submitted to apple for review. What I am wandering is wether is there a way to tell if a sqlite table view is empty. I have read about doing this, but I can't seem to find one for using SQLite. I want this because when the user first opens the app, the item view controller is empty until they refresh the table by pulling down. Is there a way to add a label that says something like, "Please refresh", but only when the table is empty?

select count(*) from some_table;
If that returns 0 then the table is empty. Of course if you already have a query against a table that returns all rows and you get back zero rows then you know the table is empty.
If you know there is an empty table then setup your table view's data source with 1 row that displays your "please refresh" message.
But if there is no data, what is the point of refreshing? And if the user can refresh, then why not do it automatically for the user? Why make the user do the refresh?

On your viewDidLoad method, you must get all the feed from sqlite... so start a loading view on viewDidLoad.. and remove that view when you get all the views.... then you could check your list of items for count and when the count == 0, display what ever message you want to display.

Related

Changing the title of the table when an spesefic that changes in table in Swift

I have a table view which I populate it with the data that I receive from the database. There is an element in my table which is the Date that data added to the database and I'm showing it. All the data are sorted in order of the date in the database, therefore there is no problem with sorting them is my app. When the user is scrolling down the table he is seeing the date but I need to make that date to be set as a header to the top of the table view and when the user passes that data the date get changed in the header.
I found nothing related in StackOverflow, But I found a tutorial in YouTube but it had a problem which was just for collection view and I'm not the good one that I was looking for. could anybody give me a clue or a similar code to understand the logic and requirements
If you want to fix header at top of the table view you have to use UITableViewStylePlain style for it.
See also this question.

Adding cells and rows programmatically to a UITableView

I have a loop that runs through all of a user's address book contacts. It checks to see if any of the user's contact's phone numbers are in my server's database. The database returns an object to me that has a count property, and if the phone number was found in the database, then the object returns with a count of 1.
I need to add code to this loop, so that any time the object returns with a count of 1, a new cell and row are added to the UITableView that has already been created in the story board.
I have some method implementations already setup to control the UITableView but I can only get them to work for 1 contact and that is it. These were copied from a tutorial and I just can't get them to work for my specific purpose. I have also played around with some code from the iOS docs but I'm lost.
Isn't there a simple way to programmatically add additional cells and rows to a UITableView that has already been created in the storyboard?
If you want to add dynamic row then the simplest way to add new data in array in which yo have store data for creating rows and then call for reload of table, it will add new rows in you table.

Reload view crash with 'index 0 beyond bounds for empty array' error

My app is based on core data using MR.
I have 3 views. The three views are -
a table view where I can select an entity, when tapped it open the second view with all the relatives data and there I have a button that open the third view where the user can modify the data.
My problem is that to open the second view I have to pass from the table the row number to get the exact entity to be displayed, and here everything fine.
But if the selected entity is the last one in the table and the user modify some data that remove the last row(for example if change the category attribute of the entity), when I go back my app crash, because the row number relative that I passed from the first view doesn't exist anymore in my database.
I hope I explained it well. I know the problem, but I don't have any idea of how to solve it.
My problem is that to open the second view I have to pass from the table the row number to get the exact entity to be displayed
You should not pass the index into the table, since you know that it can change.
Alternatively, you can pass the managed object itself, or its objectID (taking into account that objectID is expensive).
In Xcode, in the left pane there's a breakpoint section (the one with the shape of an arrow… more or less). Open that section. If you hit the + button in the bottom left corner of that pane you can add an Exceptions Breakpoint. This will store the your app and highlight the section where it's crashing. From there you might be able to solve your problem fairly easily: you only need to understand why you're still trying to access that row, instead of the new index of the object. If you still need help at that point, please post the section of your code that's crashing and any related code of that class.
I solved my issue by passing the identifier of the entity instead of the row index. So now in the detail view I get my entity using the identifier instead the index.

How to find an item in core data backed table view and make it selected

When the app is launching at first there is no selected cell in the table view. Only after the user tapped one of it.
I know from the cora data database which managed object is the selected one but how could I find it and make it selected/highlighted etc in the table view?
Actually I need the index of that item in the tableview.
To store the last selected cell's index and store it is not a good solution as the database could change so I have to find it and meantime get the it's index.

Corona SDK, tableView: is there a way to force refresh- currently not showing new table entries

Is there a way to force a refresh/reload of the data on a tableView. I’m making an app where you tap a button to show a different group, in that new group you add a record to a sqlite database table and get returned to the original group with the tableView in. I need to reload this tableView to show the new value from the database.
Thanks in advance for any help!
-- populate list from table:
myList:sync( itemData )

Resources