View-ViewController Programming 

  • view controllers 
  • the building blocks of iOS development 
  • manages single user interfaces  
  • every vewi controller has a view controller 
  • every UI element that is shown as part of the view controller belongs in a view herarchy 
  • a view controller has one root view and typically many subviews 
  • in iOS, MVC binds the view and the controller together in the concept of a view controller 
  • Every iOS app has a main window, and every window has one root view controller. This is the view controller that is initially shown in the app window. Apps can have more than one window. Windows do not have any visible content of their own, so the view controller’s view provides all the content for the initial UI of the app 
  • creating views: 
  • programmatically 
  • XIB 
  • A XIB is an XML-based user interface file. It contains information about one UI. Including its views and their properties. A XIB is typically connected to a view or view controller class 
  • A XIB represents the UI information of one view or view controller class, whereas a storyboard represents many view controllers 
  • You can use XIBs for views and view controllers. The XIB itself just contains information about views and their attributes. A view controller can be represented in a XIB, but so can a UIButton sublass 
  • An important concept in XIBs is that of the File’s Owner. The File’s Owner is the class that loads the XIB at runtime, such as UIViewController subclass.  
  • When you are working with a XIB instead of a storyboard, the view controller item is the File’s Owner. So, instead of dragging to the ViewController item, you drag to File’s Owner. They are essentially the same thing: the view controller class that “owns” this Interface Builder file. 
  • Storyboard 
  • What is the difference between a XIB and a NIB? 
  • A XIB is an interface builder file in editable XML format. A NIB is that same file in a deployment-ready binary format, stored in the app binary package. That is why interface builder always mentions XIBs, and the iOS SDK’s classes and functions talk about nib and NIBs.  
  • UINavigationController 
  • Essentially a container of viewcontrollers that allows easy navigation by pushing and poping view controllers like a stack 
  • Navigation Bar 
  • The central component is a navigation controller is its navigation bar. This bar displays the title of a view controller, and you can also use it to go back to a previous view controller. iOS apps use them for many more things, such as primary buttons like save or edit 
  • Navigation item 
  • Every view controller that is part of a navigation controller need to have a  navigation item. This item is used to display information about a view controller in the navigation bar. The navigation bar will, for example, use the title of the previous view controller to display its name next to the Back button in the navigation bar. You also use the navigation items to display secondary buttons in the navigation bar. 
  • Toolbar 
  • A navigation controller can optionally use a second bar at the bottom of the screen – the toolbar. You can add buttons to this toolbar, for secondary actions. Toolbars are not common in iOS apps anymore, except for custom keyboard inputs, because app UIs have gotten much more minimal 
  • Requires a root view controller  
  • This pushing and popping view controllers onto the stack is what makes a navigation controller work. It is a navigation controller’s most important affordance, and a often approach in practical iOS development 
  • Storyboards and segues 
  • Storyboards 
  • You can use storyboards to graphically lay out the user’s path – called flow – throughout your iOS app. Just like the storyboard of a movie, a storyboard in Xcode describes how we go from one scene to the next 
  • Scene 
  • A storyboard is made from a swquence of scenes. Every scene represents view controllers and its view 
  • Segue 
  • Scenes are connected with segues. They are the transitions from one scene to the next; from one view controller to the next.  
  • An advantage of using storyboards is organizing many view controllers in one interface builder file 
  •  
  •  
  • Storyboards can help you move data from one view controller to the next, by using segues 
  • Storyboards are useful for prototyping apps. You can quickly mock an app in a storyboard without writing lots of boilerplate code.  
  • Clean view controllers 
  • Use proper OOP 
  • Use design patterns 
  • Minimize delegation 
  • Use extensions 
  • AutoLayout 
  • Auto layout is a constraint-based layout system 
  • It allows developers to create an adaptive UI that responds appropriately to changes in screen size and device orientation 
  • Without using auto layout , it would be very hard for you to create an app that supports all screen resolutions 
  • Points vs pixels 
  • Apple uses points to layout UI 
  • Apple handles transitioning points to pixels under the hood  
  • Auto layout allows developers to create an adaptive UI that responds approprietly to changes in screen size and device orientation 
  • i.e “a button should both be centered horizontally and vertically”, regardless of the screen resolution and orientation 
  • here we have two constraints 
  • center horizontally 
  • center vertically 
  • auto layout is all about constraints. While we describe the constraints in words, the constraints in auto layout are expressed in mathematical form.  

RESOURCES:

Introduction to Auto Layout 

https://www.appcoda.com/learnswift/auto-layout-intro.html