Post on 20-Aug-2015
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.
iabdulrazzaq@outlook.com 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.
iabdulrazzaq@outlook.com 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:
iabdulrazzaq@outlook.com 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.
iabdulrazzaq@outlook.com 5Eng. Abdulrazzaq Alnajjar
Outlets
• Outlets are special Objective-C class properties that are declared using the keyword IBOutlet.
iabdulrazzaq@outlook.com 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.
iabdulrazzaq@outlook.com 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.
iabdulrazzaq@outlook.com 9Eng. Abdulrazzaq Alnajjar
Buttons and Action Method
6) Control-dragging to source code
iabdulrazzaq@outlook.com 10Eng. Abdulrazzaq Alnajjar
Buttons and Action Method
7) Connection: Action, Name: buttonPressed, Press connect.
iabdulrazzaq@outlook.com 11Eng. Abdulrazzaq Alnajjar
Buttons and Action Method
iabdulrazzaq@outlook.com
8) Header file should now look like this:
12Eng. Abdulrazzaq Alnajjar
Buttons and Action Method
9) Impelementation file added a method stub
iabdulrazzaq@outlook.com 13Eng. Abdulrazzaq Alnajjar
Label and Outlet
• header file after adding outlet
iabdulrazzaq@outlook.com 15Eng. Abdulrazzaq Alnajjar
Action Method
iabdulrazzaq@outlook.com 16
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.
iabdulrazzaq@outlook.com 17Eng. Abdulrazzaq Alnajjar