Saturday, July 18, 2015

iOS Storyboard - A Few Notes From Apple Tutorial

Displaying Static content in table view. 

This is mainly used if we want to quickly produce an application with some predefined cells, rather than doing something in the code. Below simple steps can select the Static cells option instead of the Dynamic prototype option which the one selected by default. 

. Select the table view, 
2. on the right attribute inspector panel, select “Content” As static cells  
3. This adds three cells to the table view. Now we can select first cell and In the attribute inspector, change the Style to Basic or any of the 4 options available. And change the values of the different sections accordingly 
4. We can copy paste the cell and make enough cell to make a prototype. 


This actually establishes a root view controller relationship. This means that the view for the content displayed below the navigation bar will be the tableview. The storyboard entry point is now at the navigation controller because the navigation controller holds all of the content that displayed in the app.  

Now the task is to configure the navigation bar. We need navigational elements such as Back, an additional button such as Add. 

The essential point is that the navigation controllers doesnt have any of the navigation items defined. It picks the navigation bar elements from the ViewController that it is current displaying. With this in mind, we need to configure the Current View Controller i.e. the TAbleViewController to have the navigation elements. 

First of all the title of the navigation bar. This is set by the following steps. 

- On the scene that contains the view controller, there will be a Navigation bar item. Select and just set the title to the one desired. Thats All! 



To add a bar button, just drag and drop a Bar button from the object library and place on to the navigation bar of the selected View Controller. 

Now to show a different view Controller when user press on + Button, we can do that by control dragging the + button and dragging on to the new VC. When adding segue, the Show option is to push the view controller. In case if we want to present modally, that also is an option. When presenting the controller modally, the navigation bar is not getting associated with the controller. The navigation bar get associated in the same way as done initially, i.e. Editor > Embed In > Navigation Controller 

All things are almost done. One item remaining is to navigate back.  Different types of Segues are show and modal segues, one additional segue type is unwind segue. The unwind segue allows user to go back from one scene to another and it also provides a place for a developer to add code that get executed when users navigate to the previous scene. 

To do that, first on the destination view controller, add a method that accepts the UIStoryBoardSegue and returns an IBAction. Now, just add a Bar button to the navigation bar and cotnroll drag that to the Exit icon on the scene. This brings up the method that is added in the destinationView controller like the below. 







References:


No comments:

Post a Comment