Question on View Controller's view
When we access View Controller’s view property, does it always represent the entire screen or it can be partial?
Indirectly speaking, does a View Controller can have multiple view properties ?
- How can I load storyboard programmatically from class?
- Make Navigation Bar stretch behind status bar in xCode 5 / iOS7
- Is it advisable to add a UIViewController's view to another UIViewController's view?
- How to change inactive icon/text color on tab bar?
- How to build Cocoa Touch Framework for i386 and x86_64 architecture?
- how to know if current architecture is i386 or x86_64 in macs? (Xcode)
2 Solutions Collect From Internet About “Question on View Controller's view”
donkim is right but don’t take my word for it 😉
See this post by Rincewind: https://devforums.apple.com/thread/81930 and any number of older comments from other Apple employees on their forums.
If I’m understanding what you are
saying, you’ve created another view
controller (BlueViewController) and
added its view as a subview of another
view controller? If so, then this is
covered by the docs – specifically to
say not to do that because it is not
A view controller is
meant to manage an entire screen’s
worth of content. If you want to
subdivide your content further, then
it is recommended that you use objects
other than subclasses of a
UIViewController to manage those
subregions and manage those objects
with a UIViewController subclass.
In addition we have the UIViewController class reference which states:
You use each instance of UIViewController to manage a view hierarchy. A typical view hierarchy consists of a root view—a reference to which is available in the view property of this class—and usually one or more subviews presenting the actual content. On iPhone and iPod touch, the root view typically fills the entire screen but on iPad this view may fill only part of the screen. In both cases, the view controller is responsible for managing the entire view hierarchy, including all subviews.
and also the View Controller Programming Guide for iOS:
The root view acts as the container for all other views associated with your view controller. You typically define the frame for this view to match the size of the application window, which itself should fill the screen. However, the view controller also adjusts the frame size as needed to accommodate the presence of assorted views, such as the system status bar, a navigation bar, or a tab bar.
Unfortunately none of those are as explicit as I would like about why UIViewController makes these assumptions and when it might be safe to break them. From what I can tell without access to UIKit code somewhere UIKit assumes a single view controller will be responsible for a given screen worth of content. In some cases it therefore sends messages like -viewWillAppear: or -didRecieveMemoryWarning to only one (or maybe only some) view controllers if you have multiple view controllers visible in a single window. It should be possible to demonstrate this in at least a couple of different ways though I haven’t tested all of these recently so I’m going off of other user’s reported problems.
Nested view controllers will not receive -didReceiveMemoryWarning
Multiple view controller’s view will not be rotated if rotation occurs while a modal view controller is presented and the modal is then dismissed.
View controllers’ views are sometimes expected to fill the window and be opaque so the content drawn in regions of the window they do not cover can be undefined. Trying to present a modal view controller which did not fill the screen would not render underlying views, at least in iOS 3.1.x or whatever the last version I tried was.
To try to directly answer hmthur’s question. A UIViewController should have a single root view (its ‘view’ property) which fills the window and which can handle being resized to fit status bars, tab bars, and so on. That controller may have any number of sub views of that root view and properties which reference those sub views.
As a further update consider this thread on “Creating container UIViewController subclasses?” on the Apple developer forums (discussing setting
parentViewController in order to build custom container view controllers).
All UIKit ivars are considered private and their direct access is unsupported, including access through setValue:forKey:. The method that sets this ivar is also private.
As for this ivar [parentViewController], I will warn you that its behavior is likely to change.
Unfortunately I don’t have any good suggestions for alternatives, though for what it’s worth we do recognize the difficulty in creating container view controllers.
According to Jonah in this question, a view in a
UIViewController should be assumed to fill up the entire screen. I’ve written apps that have a view of a
UIViewController not take the entire screen and it’s worked great for me.
For your second question, any
UIView can add other
UIViews via the
addSubview: method. So yes, in a sense, there can be multiple views in the
UIViewController (though there will only be the one
- Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP,subcode=0x0)
- method syntax in objective-c
- Integrate Linphone app to my iOS app
- Enable or Disable Iphone Push Notifications inside the app
- How can you display info screen on iPhone during call
- iPhone running iOS 8.3 shows up as ineligible in Xcode 6.2
- Xcode Playground Timeline empty
- swift 3 error : Argument labels '(_:)' do not match any available overloads
- iOS Memory Management — Other Processes RAM Increasing
- How to play Sound File In Silent Mode iPhone sdk?
- RestKit: How to handle empty response.body?
- iPhone RestKit how to enable RKLogDebug?
- Returning from method inside a @synchronized block
- How would you scan an array of strings for a set of substrings in objective-c?
- Objective c doesn't like my unichars?