Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of Fragment (Android) in iOS

I want to know if there is a way to use some view controllers within a view controller which provides the same functionality as Fragments in Android? I want to use custom view controllers so I do not want to use NSTabViewController, UISplitViewController etc.

like image 274
Sarasranglt Avatar asked Jan 27 '15 10:01

Sarasranglt


People also ask

Are fragments still used in Android?

Using the support library, fragments are supported back to all relevant Android versions. Fragments encapsulate views and logic so that it is easier to reuse within activities.

Is a fragment a view Android?

Because an Android fragment is not a view, adding it to an activity looks somewhat different than adding a view (e.g. TextView ). A fragment is added to a ViewGroup inside the activity. The fragment's view is displayed inside this ViewGroup .

What is a fragment in Android app?

A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment.

Why we use fragments instead of activities?

A fragment has its own layout and its own behavior with its own lifecycle callbacks. You can add or remove fragments in an activity while the activity is running. You can combine multiple fragments in a single activity to build a multi-pane UI. A fragment can be used in multiple activities.


1 Answers

Container View Controllers allow to include child view controller inside another view controller. Take a look at the docs by clicking on the "more..." link in the class overview.

Implementing a Container View Controller
A custom UIViewController subclass can also act as a container view controller. A container view controller manages the presentation of content of other view controllers it owns, also known as its child view controllers. A child's view can be presented as-is or in conjunction with views owned by the container view controller....

Using them in storyboards is as simple as dragging the Container View to your view controller.

enter image description here

And Xcode will automatically add a child view controller to it

enter image description here

like image 82
Tomas Camin Avatar answered Oct 12 '22 07:10

Tomas Camin