tags:

views:

32

answers:

2

Hello all,

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.

+1  A: 

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.

Paul Lynch
What does mean, How to do "Insert the data into your model" ?
He means your implementation of cellForRowAtIndexPath: needs to return the correct cells that include your newly inserted data. When you send reloadData to the table, the table will call cellForRowAtIndexPath: to get the cells again.
progrmr
I am not clear on those. I don't know how do i insert some rows in the middle of tableview. Lets say i have five rows in tableview which has some data(image, label etc), i want to insert one NEW ROW after the first row, when clicking on first row of the existing table, How do i achieve it?
+2  A: 

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.

TechZen