Pages

How we use delegate property of a View Controller in other View Controller

Consider a statement :                                   "UITableView.delegate = self"
Now tell me what is the meaning of this statement && why we use it in our controller. Well meaning is exactly the same as you might anticipated, we are setting the delegate property of the UITableView to out view controller. But think about it why we use it here in the controller. There are two reason:
1.) First on is that when we are creating our View Controller programmatically then we need to set this in our controller because we don's have storyboard by which we can make this conection. We are helpless in this case.

2.) Second reason is that use will use this statement when we need to set the delegate property of one view controller's scene on the storyboard to other view controller's file. For example when we create a project we will have two files, one is Appdelegate.Swift file && second is ViewController.Swift file && a storyboard file corresponding to it. What if we are in a need of using the delegate property of ViewController;s scene in Appdelegate.Swift file, then we need to use this statement in our controller.

Here also even though storyboard is available but we can't make connection through it. Before we know why can't we do this understand what actually a storyboard is: A storyboard is basically just like a nib file but unlike nib file a storyboard is not loaded all at once, Instead corresponding to any event that causes any scene to be activated will only load only particular scene's object graph that relates to it means to say is that objects on the storyboard  won't exists all at the same time. And since Interface Builder has no way to know which scene will co-exists so it forbids you from making any connection from objects in one scene to the object in another scene. That's the main reason that we can't make this connection using storyboard.