The Model-View-Controller Paradigm
• Model-View-Controller (MVC) is a very logical way of dividing the code that makes up a GUI-based application.
• The MVC pattern divides all functionality into three distinct categories:– Model: The classes that hold your application’s data.– View: Made up of the windows, controls, and other
elements that the user can see and interact with.– Controller: The code that binds together the model
and view. It contains the application logic that decides how to handle the user’s inputs.
[email protected] 2Eng. Abdulrazzaq Alnajjar
Looking at the View Controller
• The Button Fun folder should contain four source code files (the ones that end in .h or .m) and a single nib file.
[email protected] 3Eng. Abdulrazzaq Alnajjar
Looking at the View Controller
• The controller class called BIDViewController is responsible for managing our application’s view.
• contents of the BIDViewController header file:
[email protected] 4Eng. Abdulrazzaq Alnajjar
Outlets and Actions
• A controller class can refer to objects in a nib file by using a special kind of property called an outlet.
• interface objects in nib file can be set up to trigger special methods in controller class. These special methods are known as action methods.
[email protected] 5Eng. Abdulrazzaq Alnajjar
Outlets
• Outlets are special Objective-C class properties that are declared using the keyword IBOutlet.
[email protected] 6Eng. Abdulrazzaq Alnajjar
Actions
• Actions are methods that are declared with a special return type, IBAction, which tells Interface Builder that this method can be triggered by a control in a nib file.
[email protected] 7Eng. Abdulrazzaq Alnajjar
Buttons and Action Method
1) Object library
2) Round Rect Button.(Drag)
3) View (Drop)
4) Edit the button’s title.
5) Show the Assistant Editor.
[email protected] 9Eng. Abdulrazzaq Alnajjar
Buttons and Action Method
6) Control-dragging to source code
[email protected] 10Eng. Abdulrazzaq Alnajjar
Buttons and Action Method
7) Connection: Action, Name: buttonPressed, Press connect.
[email protected] 11Eng. Abdulrazzaq Alnajjar
Buttons and Action Method
8) Header file should now look like this:
12Eng. Abdulrazzaq Alnajjar
Buttons and Action Method
9) Impelementation file added a method stub
[email protected] 13Eng. Abdulrazzaq Alnajjar
Action Method
Take the title of the button
Put the title in a string
Equal the string to the label
Eng. Abdulrazzaq Alnajjar
Application Delegate
• Objects that take responsibility for doing certain tasks on behalf of another object.
• Every iOS application has one, and only one.
[email protected] 17Eng. Abdulrazzaq Alnajjar