Tutorial details

@Optional @required PROTOCOLS | App Code for Sale | Preview

@Optional @required PROTOCOLS | iOS Tutorial

What you should know about protocols

Overview PAGE TOP

Hello everyone !!! in previous posts we learned how to trigger an action/method. And now in this tutorials we are going to learn about protocols!!

So basically what is called an protocol. The textbook definitions go like "Set of rules". And ofcourse in objective C too it is an set of rules.

In my previous post you might have learned about delegates. So protocols play an important role with the delegates. Will show you how,check out the image below


In the above image ,i have created a IBOutlet UITableView in .h file . Don't panic, table view just enables us to create a table , i took this example to explain about the protocols. Right click on UITableView and go to jump to definitions ,that is the delegate window.


Now in the delegate window if you scroll down, there will two keywords under @protocol keyword,they are @optional and @required . So just imagine for table we need the number of rows,and number of cells in one row etc. So the number of rows is a MUST USE delegate ,because without the numberOfRowsInSection delegate a table cannot be designed . Similarly without knowing how many cells in the table a table cannot be designed . Since these are the important delegates ,and it is placed under @required . On the other hand ,a table can be separated in different sections ,and moreover we can add a footer and header section . These all delegates come under @optional keyword . Since we may or may not use these delegates ,and if we did not use also ,it is not going to affect our tableview.So for each UI declarations we give in .h file ,we have corresponding @optional @requried delegates. And these delegates are known as the @protocol , defines a set of rules that a programmer must follow when creating UI's like UITableView .

Similarly there are other @protocols in other UI's . Feel free to ask any doubts!! Cheers!!!

Reference PAGE TOP


0 Comments Leave a comment

Please login in order to leave a comment.

Newest first

to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.