Designing with Introspection

Slides:



Advertisements
Similar presentations
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
Advertisements

SMART Board Basics Using Notebook Software 10 This and other resources available at Smart Technologies:
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
My Penguin Math Book By:. I see How many penguins do you see? Count them & type the number in the box penguins.
Create a calculator– 2nd iPhone programming exercise CSE 391 Fall 2012.
PowerPoint Practice Exercise
Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.
The First Program. Step 1  File->New Project Create a project named “HelloWorld”, and select View Based Application from the icons on the right.
NAMESPACES AND VISUAL INHERITANCE. OBJECTIVES In this chapter, I will cover the following: Using namespaces Visual inheritance.
My Penguin Math Book By:. I see How many penguins do you see? Count them & type the number in the box penguins.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Friday, August 29, 2014 CSCI 351 – Mobile Applications Development.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
Using Draw Tools C 2012jkc. Click File on the menu bar and select Page Setup on the drop- down menu to get the Page Setup dialog box. Under the Margins.
HTML Tables. Start of page where we want to place a table.
1b – Inside Visual Studio Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Test. A software house decides to develop a DVD renting program. The product manager identifies the following requirements: Every DVD will have a title,
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Lesson 13: Building Web Forms Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver CS6.
Copyright ©: SAMSUNG & Samsung Hope for Youth. All rights reserved Tutorials Software: Building apps Suitable for: Advanced.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Xcode Presentation Tom Pletzke. Creating App from template Launch Xcode Select Tabbed Application.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Lehigh University Introduction to Flash MX Sharmeen Mecklai.
IE 411/511: Visual Programming for Industrial Applications
iOS components in Swift
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Support.ebsco.com EBSCOhost Visual Search Tutorial.
1 Designing with a UIToolBar iPhone/iPad, iOS Development Tutorial.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
IOS with Swift Hello world app.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Using Pro-Engineer to Create 3 Dimensional Shapes Kevin Manner Kevin Manner Tim Reynolds Tim Reynolds Thuy Tran Thuy Tran Vuong Nguyen Vuong Nguyen.
How to create a PowerPoint By: Abby Haehn. How to Start Go to your Launchpad, located in your dock Click on the P You should get a format screen Choose.
Orientation Configuration adapting to orientation changes.
PowerPoint Practice Exercise 1.Save this file on your computer. 2.Open this file in PowerPoint 3.Edit each slide according to the instructions provided.
1 UI Alert View iPhone/iPad, iOS Development Tutorial.
Lecture 10 Using Interface Builder to create Mac Applications.
The iOS Platform and SDK. iOS iPhoneiPad Mini iPad.
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
1.Begin by opening VB 2.Click New Project or the icon Hello World Tutorial NOTE: depending on your version of VB – the images might be slightly different.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Learning the Basics of ArcMap 3.3 Updated 4/27/2010 Using Arc/View pt. 1 1.
WebViews UIWebView. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and xib) that manages.
Views in iOS Mobile apps for iPhone & iPad Telerik Software Academy
Chapter 2: The Visual Studio .NET Development Environment
Developer 2000 CSE 4504/6504 Lab.
Chapter 1: An Introduction to Visual Basic 2015
iOS - First Application Anatomy
PDS OFFICE: STANDARD REPORTS & BEGINNING SELECTIONS
The Alice Interface.
CSCI 351 – Mobile Applications Development
EEC-492/693/793 iPhone Application Development
My Penguin Math Book By:
EEC-492/693/793 iPhone Application Development
Android Studio Hello World
EEC-492/693/793 iPhone Application Development
My Penguin Math Book By:
My Penguin Math Book By:
My Penguin Math Book By:
My Penguin Math Book By:
Learning the Basics of ArcMap 3.3 Updated 4/27/2010
My Penguin Math Book By:
Primary National Strategy
EEC-492/693/793 iPhone Application Development
Chapter 1 Introducing Small Basic
PowerPoint Practice Exercise
Presentation transcript:

Designing with Introspection iPhone/iPad, iOS Development Tutorial

Dynamic Binding Objective – C allows dynamic binding: a feature that makes it possible to postpone decisions about what classes we are dealing until runtime. In order to make this kind of decision however, we need to be able to determine exactly what class or classes we are dealing with.

Open a new “Single View” app Start Xcode, choose “Create a new Xcode project,” select the Single View Application template, and click Next. Select “Use Auto Reference Counting” Don’t select the storyboard. Don’t really need it for this application. Select ‘iPhone’ as the app type

Create the Interface Drag a “View” from the library to the window. Put eight labels in the view. You should have a large white square which is a UIView object containing eight labels. All other controls are on the main view.

Create the interface

Add items to ViewController.h Open ViewController.h file, and make changes as shown below: (IBAction)test1Pressed:(UIButton *)sender; (IBAction)test2Pressed:(UIButton *)sender (IBAction)test3Pressed:(UIButton *)sender; (IBAction)test4Pressed:(UIButton *)sender;

ViewController.h We are only declaring action methods for the four UIButton objects. We don’t need IBOutlets in this app; We are going to find controls in the view by inspecting the properties of the objects inside the main view using introspection.

- (IBAction)test1Pressed:(UIButton. )sender { for (UIView - (IBAction)test1Pressed:(UIButton *)sender {     for (UIView *aView in self.view.subviews) {         if ([aView isMemberOfClass:[UILabel class]]) {             aView.backgroundColor = [UIColor redColor];         }     } } - (IBAction)test2Pressed:(UIButton *)sender {     for (UIView *aView in self.view.subviews) {         if ([aView isKindOfClass:[UIView class]]) {             aView.backgroundColor = [UIColor blueColor];         }     } } - (IBAction)test3Pressed:(UIButton *)sender {     for (id aView in self.view.subviews) {         if ([aView canPerformAction:@selector(setText:) withSender:sender]) {             [aView setText:@"Hello!"];         }     } } - (IBAction)test4Pressed:(UIButton *)sender {     for (UIView *aView in self.view.subviews) {         if ([aView isMemberOfClass:[UIView class]]) {             for (UILabel *aLabel in aView.subviews) {                 aLabel.backgroundColor = [UIColor greenColor];             }         }     } }

ViewController.m Add the methods immediately after the @implementation line in the .m file. Run the application and observe the results of pressing each button.

What are we doing? The first test looks at all subviews of the main view. It then uses isMemberOfClass on each one to determine if each view is a UILabel. The isMemberOfClass method returns YES if an object is an instance of one specific class. So if this method finds a UILabel that is a subview of the main view, it will set its background color to red:

Test1 Button

What are we doing? The label objects inside the white square UIView do not get their background color set to red. This is because these labels are subviews of a subview, not direct subviews of the main view. The second test looks for all subviews of the main view that are descended from UIView. This is accomplished by calling isKindOfClass. Since all controls are descendents of UIView, this method will change the background color of all of the subviews to blue:

Test2 Button

What did we do? Again, the background color of the labels internal to the white square view is unchanged, since the default background color of a UILabel is transparent. Test 3 searches all the subviews of the main view for objects that have a setText method. It accomplishes this by using the canPerformAction method. Since the only subview of the main view that has a setText: method is the UILabel at the top, the method changes the text to “Hello!”:

Test3 Button

What did we do? Test 4 shows one way to get to the label objects in the white square view. First, we must find a subview of the main view that is a member of the UIView class. Then, we look for subviews of that view that are UILabels, and set their background color to green:

Test4 Button

Summary Introspection is useful when we have a large number of similar controls and we want to find a particular control by looking at some attribute (for example, a tag). It’s also useful when we’re using inheritance. We might want all subclasses of some class to perform a method, but only if that method is defined. Since we might not know what objects will be performing the method at compile time, we can see that introspection is an extremely powerful tool.