开发者

Tabbar with different Data

I am trying to develope an iPhone App for 3 months. I found everything myself in books or the internet. Now I have a problem that I am not able to solve myself.

I would like to develope a tabbar application with 3 tabs. In each tab is a navigation controller with a tableview.

The tableview loads the data from an XML file on the web. The difference between each 开发者_开发技巧tab is only the difference XML-url. The tableview and function should everywhere the same.

What have I done?

  • Created a tabbar application
  • Put 3 Navigation Controller in the Tab Bar Controller in the MainWindow.xib
  • Every View in each Navigation Controller points to the same "TableView" class

Now it loads on every tab the same tableview. But I just want to change the XML-URL which is loaded. But I dont know how to implementate this.

I hope that somebody can give me a hint? Thank you!


Are you sure you need a Tab Bar? You could just add an additional level of navigation on top for the sources. So your navigation controller stack would be like

UINavigationController -> SourceViewController -> ListViewController -> rest of your navigation stack.

ListViewController is a subclass of a UITableViewController which is passed the source url based on selection from SourceViewController which can be a subclass of UITableViewController too. This will save you of the repetition you are trying to avoid and is more likely a better option for the thing you need.

Now if you insist on using a Tab Bar, your stack will be more like –

UITabBarController which will have three instances of UINavigationController each with its own instance of ListViewController which like before will be initialized using a source url.

Now it may be smarter to reduce it to a single ListViewController and attaching all the navigation controllers to it. You can do this using the -tabBarController:didSelectViewController: method in the tab bar delegate. On every tab change/call, you clear the current cache that is providing data to the table view and load the appropriate cache based on the source XML of that tab.

Usually state is preserved on tab changes but using this structure you will have to do additional work to get that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜