iPhone:How do i insert few rows in the middle of existing table?
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.
精彩评论