Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

ios - UITableViewController inside a UIViewController

I'm new to iOS and objective-C and I'm having some trouble in understanding how controllers work.

In my code I have a UIViewController (with my custom controller assigned by storyboard) and inside it, together with other objects, I want to have a table handled by a different controller. What is the right way to do this?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can make that table view controller a child view controller of your UIViewController.

In the storyboard, you can do this easily by dragging a container view into your controller's view, and that will give you a child view controller automatically.

You'll want to:

  • delete the child view controller it gives you (it's just a UIViewController)
  • drag out a table view controller
  • control drag from the container view to the table view controller
  • choose "embed".

If you need to get a reference to this table view controller from the UIViewController, you can do that in prepareForSegue -- the table view controller will be the segue's destination view controller, and prepareForSegue will be called right after the controllers are instantiated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...