iPhone:How do i insert few rows in the middle of existing table? - iphone

If i want to insert few rows in the middle of the existing table, how do i approach it? Where all that i should be careful when doing such thing? Is there any good sample source available?
Appreciate your helps.
Thank you.

Tableviews don't contain data and they don't actually contain rows themselves. Instead, tableviews are just an illusion created by redisplaying the same tableviewcell objects over and over again with different data each time. The real table, the real rows, are actually in the logical data.
So, to " insert few rows in the middle of the existing table" you actually add the rows into the data that the table displays. For example, if you had a simple array of names that you display in the table, you would insert the new names into the array. Then you would call -[UITableView reload] which will cause the table to ask the datasource for the new data.
See the Table View Programing Guide for iPhone OS.

Insert the data into your model and call reloadData on the table. If you need to animate the insertion for some reason, you can use insertRowsAtIndexPaths:withRowAnimation:, but the principle if updating the model first still applies.

Related

store selected rows on PFQueryTableViewController

I have a tableview that is of type PFQueryTableViewController and gets its value from Parse cloud. The tableview works fine but now I need to allow the user to:
Select a row
Record in a column (string array) on Parse-Users table what rows have been selected (need to record on parse that - i will use these values for other things later)
When the user comes back and opens the tableview he can see what rows have been selected last time he was in the app
I am not sure if PFQueryTableViewController has any methods ready for that. Could anyone give me some guidance?
I would prefer to use parse cause there are so much stuff out of the box. But if not, that is fine as well.
Also, code samples from similar solutions would be great. Just need to know the best approach.
The table view controller is there for display, it will tell you about selection, but it won't automatically maintain a record of selected items in the back end. You need to decide on the appropriate way to store the selections (array of pointers is better than an array of strings) and update the store and table display appropriately. There is no standard approach to this.

Updating table content using SQLite?

Friends, here is my problem: I populate a table in Xcode using SQLite database. Here is what I want - If my table has 20 rows and all of them are populated, how to update the table if new data is saved in my SQLite database? I want the new information to overwrite the old one. How to do that in Xcode, any ideas? Thanks in advance! I am not sure if the info that I provided is enough, so let me know if you want some code or other stuff.
The key to what you're doing is in the routine you furnish for your table: cellForRowAtIndexPath. Basically, you can write that routine to furnish whatever data you want it to furnish. Once you know that your data has been updated, you can cause the entire table to refresh with a call to reloadData.

Obj-C, catering for 'tap for more rows' and delete without core data?

I've been adding a temporary row to the end of my table view so I can limit the amount of data loaded / improve the speed of loading the view.
However, I didn't think about the delete feature. Where they swipe right to delete a row..
In my commitEditingStyle event I have, my check to see if it is a delete, then delete row from database, removeObjectAtIndex from my data array, beginUpdates, deleteRowsAtIndexPaths and if zero items left in my table insertRowsAtIndexPath with fade, so that my no transactions row will appear then endUpdates.
I did think when I add my tap for more rows I'd assign the row index to a variable and delete this row first in the commitEditingStyle event. However, I'd then have to query my database just to add another row, then add the tap for more rows row.
Which seems a lot of work for a quick fix.
Of course, I could just do a reloadData, but this seems really bad, but might be my only option.
I do eventually want to move to Core Data, but I really need to get this release out the door, its quite a complicated screen with segmented control for different data views and tap to edit the row in another view.
Can anyone advise me about some kind of trick / event I may have missed or another approach I could quickly use in this scenario ?
Make "tap for more" your table footer view instead of another cell. You will have to do this anyway if you move to core data and NSFetchedResultsController since hacking in an extra row becomes very complex then.
Your table footer view will just be a button (or some other view styled how you like it) - this can be created on viewDidLoad and set up with actions etc. It does not form part of your data model at all, so you have nothing extra to do in your datasource methods.

NSDictionary as a data structure for objects question

I just wanted to make sure I don't need Core Data for a simple example. If I have a UITableView where the user can hit the plus sign to add new table entries, and each entry corresponds to an individual timer event, do I store each object added to the table in an NSDictionary? Thanks.
NSMutableArray would be a better choice. An array is an ordered list, just as a table is. A dictionary is not ordered, so it's not a good match for a table.
If that's confusing, try thinking about it in concrete terms. Imagine that you have a table and you've stored the data for the table in a dictionary. At some point, the table will ask it's data source -- probably your view controller -- to provide a cell for a particular row of the table. How do you figure out which entry of the dictionary corresponds to that cell? On the other hand, if you use an array, the mapping between table rows and data items is simple.

iPhone Dev - Trying to access every row of a sqlite3 table sequentially

this is my first time using SQL at all, so this might sound basic. I'm making an iPhone app that creates and uses a sqlite3 database (I'm using the libsqlite3.dylib database as well as importing "sqlite3.h"). I've been able to correctly created the database and a table in it, but now I need to know the best way to get stuff back from it.
How would I go about retrieving all the information in the table? It's very important that I be able to access each row in the order that it is in the table. What I want to do (if this helps) is get all the info from the various fields in a single row, put all that into one object, and then store the object in an array, and then do the same for the next row, and the next, etc. At the end, I should have an array with the same number of elements as I have rows in my sql table. Thank you.
My SQL is rusty, but I think you can use SELECT * FROM myTable and then iterate through the results. You can also use a LIMIT/OFFSET(1) structure if you do not want to retrieve all elements at one from your table (for example due to memory concerns).
(1) Note that this can perform unexpectedly bad, depending on your use case. Look here for more info...
How would I go about retrieving all the information in the table? It's
very important that I be able to access each row in the order that it
is in the table.
That is not how SQL works. Rows are not kept in the table in a specific order as far as SQL is concerned. The order of rows returned by a query is determined by the ORDER BY clause in the query, e.g. ORDER BY DateCreated, or ORDER BY Price.
But SQLite has a rowid virtual column that can be used for this purpose. It reflects the sequence in which the rows were inserted. Except that it might change with a VACUUM. If you make it an INTEGER PRIMARY KEY it should stay constant.
order by rowid