1. Trang chủ
  2. » Công Nghệ Thông Tin

CS193P - Lecture 7 pptx

52 239 0
Tài liệu được quét OCR, nội dung có thể không chính xác

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 52
Dung lượng 1,46 MB

Nội dung

Trang 1

CS193P - Lecture 7

Trang 2

Announcements

¢ Assignment 3 was due last night at 11:59 PM

Trang 3

Announcements

¢ Next Monday, 4/27

= Table Views, Scroll Views and Presence 2

Trang 4

Announcements

¢ This Friday:“Preparing Your App for the App Store”

¢ Next Friday: Loren Brichter of Tweetie (http://www.atebits.com)

Trang 8

Carrier John Appleseed Kate Bell Anna Haro Daniel Higgins Jr David Taylor Hank M Zakroff

How It Fits Together

Trang 9

Carrier John Appleseed Kate Bell Anna Haro Daniel Higgins Jr David Taylor Hank M Zakroff

How It Fits Together

Trang 10

Carrier John Appleseed Kate Bell Anna Haro Daniel Higgins Jr David Taylor Hank M Zakroff

How It Fits Together

¢ Top view controller’s view ¢ Top view controller’s title

Trang 11

Modifying the Navigation Stack

¢ Push to add a view controller

- Cvoid)pushViewControLler: CUIViewControLller *)viewControLler

animated: CBOOL )animated;

* Pop to remove a view controller

Trang 12

Pushing Your First View Controller

- (void)appLicatitonDidFinishLaunching // Create a navigation controLler

navControLler = [[UINavigationControLler alloc] init]; // Push the first view controller on the stack

[navControLLer pushViewControLler: firstVitewControl Ler animated:NO];

// Add the navigation controlLler’s view to the window

[window addSubview:navControlLler.view];

Trang 13

In Response to User Actions

¢ Push from within a view controller on the stack - (void)someAction: (1d)sender i // Potentially create another view controller UIViewControLler *viewController = .; L[self.navigationControLLer pushViewControLller: viewControlLler animated: YES]; b

° Almost never call pop directly!

Trang 14

Demo:

Trang 17

A Controller for Each Screen

Trang 18

Connecting View Controllers

¢ Multiple view controllers may need to share data

¢ One may need to know about what another is doing

Trang 19

How Not To Share Data

¢ Global variables or singletons

- This includes your application delegate!

¢ Direct dependencies make your code less reusable

- And more difficult to debug & test

Trang 20

Best Practices for Data Flow

¢ Figure out exactly what needs to be communicated

¢ Define input parameters for your view controller

¢ For communicating back up the hierarchy, use loose coupling

= Define a generic interface for observers (like delegation)

Controller

Trang 21

Example:

Trang 22

Demo:

Trang 24

Customizing Navigation

¢ Buttons or custom controls

Trang 25

UINavigationltem

° Describes appearance of the navigation bar

- [itle string or custom title view - Left & right bar buttons

- More properties defined in UINavigationBar.h

¢ Every view controller has a navigation item for customizing

Trang 26

Navigation Item Ownership

as

ee gl NH2,

Trang 27

Displaying a Title

¢ UlViewController already has a title property

- @propertyCnonatomic,copy) NSString *title;

¢ Navigation item inherits automatically

= Previous view controller's title is displayed in back button

Trang 28

Left & Right Buttons

¢ UlBarButtonltem

= Special object, defines appearance & behavior for items in

navigation bars and toolbars

¢ Display a string, image or predefined system item

Trang 31

Edit/Done Button

Carrier

° Very common pattern

¢ Every view controller has one available

- Target/action already set up

tes Cherry Cobbler

as

\W Chocolate Cake

self.nav1gattonTtem LeftBarButtonTtem = seLf.ediItButtonTtem; // Called when the user toggles the edit/done button

- (void)setEditing: CBOOL)editing animated: CBOOL )animated

i

// Update appearance of views

Trang 32

Custom Title View

Trang 33

Back Button

¢ Sometimes a shorter back button is needed

Trang 34

Back Button

¢ Sometimes a shorter back button is needed

self.title = @“HeLlo there, CS193P!”;

UTBarButtonTtem *heyButton = [[UTBarButtonTtem aLLoc] 1n1tWtthT1tLe:@“Hey!”

ren

self navigationiItem.backButtonItem = heyButton;

Trang 35

Demo:

Trang 38

How It Fits Together

Trang 39

How It Fits Together

Trang 40

Setting Up a Tab Bar Controller

- (void)appLicatitonDidFinishLaunching

b

// Create a tab bar controller

tabBarControLler = [[UITabBarControLler alloc] init];

// Set the array of view controllers

tabBarControLler.viewControLlers = myViewControllers;

// Add the tab bar controLller’s view to the window

Trang 41

Tab Bar Appearance

¢ View controllers can define their appearance in the tab bar

World Clock Alarm Stopwatch Timer

H9 |0 c?000(210 1)

- Title + image or system item

Trang 42

Creating Tab Bar Items

Trang 44

Demo:

Trang 45

More View Controllers

¢ What happens when a tab bar controller has too many

view controllers to display at once?

Trang 46

More View Controllers

¢ What happens when a tab bar controller has too many

view controllers to display at once?

= “More” tab bar item ——

displayed automatically

- User can navigate to Most Recent

remaining view controllers W Top Rated

C History

.>x 9302 mài we TT

Trang 47

More View Controllers

¢ What happens when a tab bar controller has too many

view controllers to display at once?

= “More” tab bar item ——

displayed automatically

- User can navigate to

Trang 49

Tab Bar + Navigation Controllers

Multiple parallel hierarchies iStanford Fingerlings 3 3 Stanford University W W* W* W W 9reviews „ Flight of the Conchords iStanford is Stanford University in the palm of your hand

Search the Stanford directory, search campus map,

Flyin' Shoes find and bookmark courses, and get scores,

schedules, and news for all Stanford varsity athletics teams All from your iPhone or iPod Touch!

Friend Opportunity

Features:

- Search for buildings / places on campus, and use

Frontin' On Debra (DJ GPS to find your location

- Search for students, faculty or anybody in the Stanford directory Tap to call/email You can even

add them to your contacts on your phone!

- Search for classes, find out where and when they're offered, and tap to call or email the

= Wn Ko 86.5

a Leh) Artists Albums Podcasts More erties Categories Top 25 oer Fed

Trang 50

Tab Bar + Navigation Controllers

Trang 51

Nesting Navigation Controllers

¢ Create a tab bar controller

tabBarControLler = [[UITabBarControLler alloc] init];

¢ Create each navigation controller

navControLler = [LUINavigationControLler alloc] init]; [navControLLer pushViewControLler: firstViewControl Ler

animated:NO];

¢ Add them to the tab bar controller

tabBarControLLler.viewControLllLers = [NSArray arrayWithObjects: navControLLer,

Ngày đăng: 12/07/2014, 12:20

w