Lecture4

advertisement

1

UIAlertView, UIActionSheet, and

Facebook Connection

Lecture 4

Organization

Part 2 – Two Common Controls and Delegate

Concept

2.1 UIAlertView

2.2 UIActionSheet

Part 3 – Facebook Connection

3.1 Facebook Role

3.2 iPhone Role

2

UIAlertView - Introduction

A UI component that pops up to catch user immediate attention and respond for some internal status changes

In Tutorial 3 Part 3.3, the following screen is shown when game ends

UIAlertView

3

UIAlertView - Introduction II

Note that you must respond by clicking the button before you can do any other action on the screen view.

For example,

Situation 1: You can try shaking the device when the

UIAlertView is shown up.

Situation 2: You can try shaking the device after you have pressed the button.

4

Analogy: Windows Alert

Windows also has similar function. For example:

When I turn off the system without saving this powerpoint file, the following alert is popped up:

5

UIAlertView – Multiple Choices

Other than catching the user attention, another useful function is to provide choices for the user.

Recall that to activate the UIAlertView:

6

UIAlertView – Multiple Choices II

Note that the “otherButtonTitles” field is nil

To provide more buttons in the UIAlertView, we can put in other string value(s) as parameter(s) of the

“otherButtonTitles” field

7

UIAlertView – Multiple Choices III

Now, we know how to create a

UIAlertView with two or more buttons.

Quick Questions:

How do we know that which button is clicked if there are multiple buttons?

Delegate Concept

8

Delegate – Basic Concept

When certain events (e.g., press a button in a

UIAlertView) occur on a certain kind of UI components

(e.g., UIAlertView), the components will call back its delegate to handle the event for it.

Register as delegate

1. VolcanoRockEscapingViewController

2. VolcanoRockEscapingViewController

Call back

(Please handle this event for me)

9

Delegate - Requirements

Now, we know the role of a delegate. However, to become a “valid” delegate, there are some requirements:

1.

The UI component can detect some events on it and allow its delegate to handle it

2.

The object has to intentionally register as the delegate of the

UI component.

3.

The object has to declare and implement the functions to handle the event

10

Delegate – Registration

When did “VolcanoRockEscapingView Controller” register as delegate of the UIAlertView?

11

Delegate – How to handle the event?

How can “VolcanoRockEscapingViewController” handle the event?

For some UI components, the SDK has provided a predefined set of handler function declaration.

The delegate can handle the event by implementing the predefined set of functions

To handle the UIAlertView event, we have to:

1.

2.

Declare in “VolcanoRockEscapingViewController.h”that it has implement the function

Implement the related function in the

“VolcanoRockEscapingViewController.m”

12

Codes Modification Required

In “VolcanoRockEscapingViewController.h” file, we need to declare that this class has implement the function

In “VolcanoRockEscapingViewController.m” file, we need to implement the following function

:

13

UIActionSheet - Introduction

Similar to that of UIAlertView, it is used to catch the user’s attention, and provide selection choices to users.

UIActionSheet

14

UIActionSheet – Introduction II

Unlike that of UIAlertView

UIActionSheet object slides up from bottom, while

UIAlertView object is popped up in the center.

UIActionSheet object is more likely to be activated by user, while UIAlertView is more likely to be activated by the change of internal status.

UIActionSheet object is mainly used to provide more choices for the user, while UIAlertView is mainly used to inform the user about the status changes

Please refer to the tutorial sheet for the objective-C codes on activation, detection of button clicked, etc.

(Very similar to that of UIAlertView  )

15

Facebook Connection - Introduction I

Facebook has provided an open source iPhone Facebook

Development Kit for iPhone developers to connect to the user’s facebook account.

Basically, the relationship between iPhone programming and facebook can be summarized as follows:

Your iPhone

App iPhone Role iPhone

Facebook

SDK

Facebook

App

Facebook

User

Account

Facebook Role

16

Facebook Connection - Introduction II

 iPhone app makes use of the iPhone Facebook

Development Kit to connect to a facebook app.

The facebook app can then act on behalf of the iPhone app to access the user’s facebook account information.

The information accessed includes, post feeds, user’s friends information, etc.

17

Procedures in Making Facebook Connection

3.1 Setup a facebook developer account and a facebook app

3.2 Setup the iPhone facebook SDK

3.3 Login facebook through iPhone

3.4 Upload photo with a message

Please refer back to the tutorial sheet for the detail descriptions

18

3.

4.

1.

2.

Challenges (Optional)

Different styles of VolcanoRock generation pattern

Different difficulty levels

Keeping best score

Any others?

19

Download