why
why

Reputation: 24851

Need I create many controllers in tabBarController?

there is one xml file in my server:

<categories type="array">
  <category><id type="integer">5</id><name>1</name></category>
  <category><id type="integer">1</id><name>2</name></category>
  <category><id type="integer">2</id><name>3</name></category>
  <category><id type="integer">3</id><name>4</name></category>
  <category><id type="integer">4</id><name>5</name></category>
</categories>

When my app start , I want to show one category one tab item on bottom, and each category page will show many food list of that category

I want to know need I create one category one controller and put them in tab controllers or create many items in tab bar, and each category share one page view ?

Upvotes: 0

Views: 89

Answers (1)

Martin R
Martin R

Reputation: 539705

You need a unique instance of a view controller for each tab item. But of course all instances can be of the same class. So you could define a class MyViewController with properties type and name and then instantiate one for each tab.

Pseudocode:

NSMutableArray *viewControllers = [NSMutableArray array];
for all categories {
    MyViewController *vc = [[MyViewController alloc] initWithNibName:...];
    vc.type = ....;
    vc.name = ....;
    [viewControllers addObject:vc];
}
tabBarController.viewControllers = viewControllers;

Upvotes: 1

Related Questions