I have 3 table views in 3 different pages, almost identical layout and functionality. I have duplicate codes for all three pages doing the same thing. What's the best way to reuse code and remove duplicity?
I had the same problem. All my tables were editable and all used the same size jQuery block of code to work on the table. After doing it this way for a while I learned how to write jQuery plugins. Now I use a table plugin that I wrote which handles my pagination, table filters and editing all in one block of code for all the tables on my sites. Over time I have improved my plugin, and now I have written other plugins which do character counting, and nice slide in effects.
Now with one line of jQuery I can run my table plugin $('#petty_table').mrtable({ url:"ajax/petty/delete_petty_line.php", tableurl:"database/petty/tables/table.php", }});
Tom Wolters
[iOS development with Swift] http://www.to-m.nl
Hi Hasan, by now you probably found out. In case you didn't I'll try to answer with my limited knowledge.
You mentioned layout and functionality. I'll devide my answer into those sections.
Layout It's easiest to create a xib for laying out the UITableViewCell. You can create one cell and easily re-use it in the tableviews.
Functionality I'm a big fan of the MVC-model, so my answer is based on that model.
Create a Model to handle the functionality, like pulling the data from somewhere (disk/database/backend). Let the Controller request the data and fill an array. Use the array in your tableview.
You'll only have to write the logic once in your model and call the data from the controllers you like.
Every logic I need, I add it into a model. That way I never have to repeay (DRY) myself.