Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

iphone - ToolBar between UINavigationBar and UITableView?

I have a UITableViewController embedded on a UINavigationController. This tableView is an instance of NSFetchedResultsController. I need to add a Toolbar between the NavigationController's top bar and the TableViewController, but I can't figure out how to do it (I don't even know if it's possible). I want to do something like Apple did with their WWDC App (except that they don't have the TableViewController embedded in the NavigationController). I need to have some controls on the bar to drive the NSFetchedResultsController.

Some people suggested to people with similar problems to use a UITableView instead of a TVC, but I do need to have a TVC as an instance of NSFetchedResultsController.

Any ideas on how to accomplish this? Would I have to do it programmatically? If so, how?

Btw, I'm targeting iOS6+ with storyboards and ARC.

Apple's WWDC App

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The approach I prefer is to use a UIViewController at the outer level, containing your toolbar and a container view that holds the table. Then build your table in a separate UITableViewController and wire it into the container view using an embed segue. Overall, I think this makes the code more modular and easier to follow because the high-level structure is laid out in the storyboard.

The steps to use an embed segue are as follows:

  1. Control-drag from the container view to the view controller you want to embed and select the "Embed" option.
  2. Give the embed segue an identifier in the attributes inspector.
  3. Configure the table view controller in the parent's prepareForSegue method, checking for your segue's identifier.

There is an example of this in my VCollectionViewGridLayout library. Take a look at the Sort & Filter example project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...