1 / 19

UIAlertView , UIActionSheet , and Facebook Connection

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. UIAlertView - Introduction.

ludlow
Télécharger la présentation

UIAlertView , UIActionSheet , and Facebook Connection

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UIAlertView, UIActionSheet, and Facebook Connection Lecture 4

  2. 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

  3. 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

  4. 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.

  5. 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:

  6. 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: NSString * message = [NSStringstringWithFormat:@”You got %d score in %.01f s”, score, timeElapsed]; UIAlertView * av = [[UIAlertViewalloc] initWithTitle:@”Game Ended” message:message delegate:self cancelButtonTitle:@”Finish” otherButtonTitles:nil, nil, nil]; [av show];

  7. 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 NSString * message = [NSStringstringWithFormat:@”You got %d score in %.01f s”, score, timeElapsed]; UIAlertView * av = [[UIAlertViewalloc] initWithTitle:@”Game Ended” message:message delegate:self cancelButtonTitle:@”Finish” otherButtonTitles:@”Reset”, nil, nil]; [av show];

  8. 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

  9. 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. ViewController 2. ViewController Call back (Please handle this event for me)

  10. Delegate - Requirements • Now, we know the role of a delegate. However, to become a “valid” delegate, there are some requirements: • The UI component can detect some events on it and allow its delegate to handle it • The object has to intentionally register as the delegate of the UI component. • The object has to declare and implement the functions to handle the event

  11. Delegate – Registration • When did “ViewController” register as delegate of the UIAlertView? NSString * message = [NSStringstringWithFormat:@”You got %d score in %.01f s”, score, timeElapsed]; UIAlertView * av = [[UIAlertViewalloc] initWithTitle:@”Game Ended” message:message delegate:self cancelButtonTitle:@”Finish” otherButtonTitles:@”Reset”, nil, nil]; [av show];

  12. Delegate – How to handle the event? • How can “ViewController” 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: • Declare in “ViewController.h”that it has implement the function • Implement the related function in the “ViewController.m”

  13. Codes Modification Required In “ViewController.h” file, we need to declare that this class has implement the function In “ViewController.m” file, we need to implement the following function:

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

  15. UIActionSheet – Introduction II • Unlike that of UIAlertView • UIActionSheet object slides up from bottom, while UIAlertView object is popped up in the center. • UIActionSheetobject 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)

  16. 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: Facebook User Account Your iPhone App iPhone Facebook SDK Facebook App iPhone Role Facebook Role

  17. 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.

  18. Procedures in Making Facebook Connection • 3.1 Setup a facebookapp to obtain an App ID • 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 detailed descriptions

  19. Challenges (Optional) • A button to pause the game and resume the game. Two image files “ButtonPause.png” and “ButtonPlay.png” are provided in the website. • A grace (or superman) period when the man was hit by a rock. • Uploading the screen capture of your app to the facebook instead of the predefined picture. The related codes for doing the screen capture are put into the “additionalFile3.txt”. However, some more steps are necessary, and this part is left for you to discover. Any others?

More Related