tags:

views:

24

answers:

1

I'm new to iPhone development and I am writing an iPhone app that needs two different table views, which are selectable using a button bar or tab bar. These table views are both the same size, but only cover about two thirds of the screen from the bottom up. The top portion of the screen remains the same when either of these tables is displayed. I'd also like to animate (flip) these views when the user selects one or the other.

The view that these two tables will be displayed on is the detail view of my app where the user has already selected an item from the primary screen's table. I'm using a UINavigationController to manage the primary and detail views and I have this working. I also have the first of these two detail tables working as part of my detail view, but I think it makes more sense to isolate the code for these two tables and not duplicate all of the code for the part of the detail view that doesn't change.

I don't really care how these two table views are created (either in code or via IB). I've tried several things and I can't seem to figure it out. Any help or ideas (with sample code) would be greatly appreciated!

A: 

There are two approaches for this:

1) Actually only have one table view. Change the code that is run in the delegate functions according to which tableview you want to see the results from. I've used this with tables based on core data, and just changed the predicate to get different data back. My cellForRowAtIndexPath just returns the right type of cell according to the data it gets.

2) Make each table a tableviewcontroller. Add them both by alloc/init'ing them then

[self.view addSubview:tvc1.view];

[self.view addSubview:tvc2.view];

then hide the one you don't want to see. You will need to set frame etc but that's trivial.

If you want to animate between two views just use a basic transformation (ask that as a separate question if you can't find it, but its not hard and probably covered here already)

Andiih
OK, so I need a uitableviewcontroller for each uitableview even though I'm only adding the "view" from the uitableviewcontroller to the view of the base uinavigationcontroller? That's probably where I went wrong. I'm just trying to add a uitableview to a "content" view I added in the uinavigationcontroller xib file.
Ron Flax
yes - by having the two controllers you get to separate out your delegates for each table view and supply the right data to each. Option 1 gives you one table view and one controller if you prefer that approach.
Andiih
Excellent! Thanks for the pointers.
Ron Flax