views:

68

answers:

2

Hi there

I have a general question regarding UITableViews.

here is my situation.

I have a view with a couple of buttons and a UITableView, by pressing a button, the UITableView's Content should change. I use Custom Table Cells (the same cells in every seperate table) but of course with different content.

I'm not sure if It is good practice to define 3 UITableView instances within my view and to switch between those when clicking a button.

also i don't know what my program should do when one of the buttons is pressed (destroy the old view? how to set a new view? overlay the new vie over the old? and then how to get the old one back once another button is pressed)...

as you see, lots of rather general questions.. maybe i was searching the wrong way, but i couldn't find an article on the web that would provide me with the necessary information.

thank you for your reply! greets

sam

A: 

I really depends on both how you're transitioning between the tableviews, and their styles. If you don't have any sort of animation when switching tables, and they're all the same size, then I'd recommend using a single view, and doing what you have to do within your delegate/dataSource methods. If you're showing 'table 1', return one set of data, and 'table 2', another.

If, however, the tables are different styles (grouped vs. plain), you'll need to have different views. Also, if you're animating one table out while another is coming it, you'll need multiple views. Just layout three tables in IB, but set two of them to 'hidden'. When it's time to switch, hide the currently visible table and show the new one. Alternatively, you could use +[UIView beginAnimation:context:] to fade the old one out and the new one in.

Ben Gottlieb
thank you very much for your help. I'm currently implementing severall TableViews/Controllers and hide / show them, as you recommended. the only thing that worries me a bit, is the fact, that i probably need about 8 tableviews. maybe bentford's approach with solely exchanging datasources would be a more propper way.. on the other hand, I'll probably need to add some table-specific details at some point in the future...anyway, thank you very much and have a nice day!
samsam
A: 

First off, you could do this either way and you probably wouldn't notice a bit of difference unless your tableviews had 1000+ rows each.

The iPhone runs faster than you might realize.

With that said, memory is your most precious resource, and in some cases using too much can cause your app to get closed.

My recommendation is use one tableview and just swap out the datasource.

bentford
thank you for your help, i've currently solved my problem the way ben gottlieb explained it to me. however I tried to implement your solution as well.I've experienced the problem, that my TableView didn't get updated with the "new data" after switching the datasource like that:[tableViewInstance setDataSource:nextController];[tableViewInstance setDelegate:nextController];[tableViewInstance reloadData];I'm sure I missed out on something, couldn't figure out what it is at the moment.thanks again for your kind helpsam
samsam