0

My problem is the following:

I am making an iPhone app that is primarily based on table view controllers. I need to be able to create data for the table view during runtime. I also need to create deeper levels during runtime. ie. I need to be able to click on the row and it should take me to a new table view which is empty. Additionally i need to ideally be able to keep making data and going deeper and deeper infinitely. The data created is stored in core data. I already have found a way to link which data is shown in each table view.

My question is this: Is it ok for each new table view to be created in a new uitableviewcontroller? that is how I have done it.

For example. If I click on "Varun" on the tableviewcontroller row. It will create a new tableviewcontroller during runtime and show me an empty table view. if i add data there and go back to varun and then click on it again, the data should be there.

So should I dynamically create tableviewcontrollers for each new tableview?

Thanks!

I'm extremely sorry if I wasn't clear. It is a very hard concepts to explain!

Thanks again!

Prasad G
  • 6,702
  • 7
  • 42
  • 65
VarunMurali
  • 413
  • 1
  • 6
  • 17

2 Answers2

0

Hy there. Usually every view has it's own instance of a UIViewController-subclass so there's absolutely no problem there. You would even have different classes for the individual views. Example: The DepartmentListViewController shows all departments and pushes to the StaffViewController which might show a list of employees.

This Apple Document gives you a good overview of UIViewControllers

I would highly recommend that you use storyboards which are especially useful for data-centric apps (as opposed to a game etc.).

The storyboard engine instantiates your ViewControllers for you and you can set properties on them before they get displayed. I made a post which sums up the advantages of storyboards:

https://stackoverflow.com/a/8574345/784318

Check out this tutorial which seems to give a good overview on storyboards. Since iOS 5.0 you can also create static cells and prototype cells in a UITableView, which I think are highly useful additions to the SDK.

For a more in-depth view on Storyboards and Tableviews you should definetly check out the WWDC 2012 (2011) sessions about Storyboards and UITableviews.

http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/Art/after_modal_segue.jpg

Community
  • 1
  • 1
Besi
  • 22,579
  • 24
  • 131
  • 223
  • Hi! Thanks for so much information! Another question. Can this be done during runtime? Can I make unlimited controllers using storyboards? Thanks! – VarunMurali Jul 11 '12 at 06:20
  • Yes, since you can add segues from a ViewController to itself. This might be a bit trickier to do because you might have to handle the depth of the nesting but it is definitely possible. – Besi Jul 11 '12 at 07:49
0

You should implement code in -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    YourTableViewController *yourTableView = [[YourTableViewController alloc] initWithStyle:UITableViewStylePlain];
   [self.navigationController pushViewController:yourTableView animated:YES];

}

I think it will be helpful to you.

Prasad G
  • 6,702
  • 7
  • 42
  • 65
  • Hi! Yup thats exactly what i am doing :) I wanted to make sure that making a `UITableViewController` for every `UITableView` is OK. Thanks! – VarunMurali Jul 11 '12 at 06:17