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

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

How It Fits Together ¢ Top view controller’s view ¢ Top view controller’s title... How It Fits Together ¢ Top view controller’s view ¢ Top view controller’s title ¢ Previous view cont

Trang 1

CS193P - Lecture 7

iPhone Application Development Navigation & Tab Bar Controllers

Trang 2

Announcements

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

¢ Presence 1 is due on Tuesday 4/28

Trang 3

Announcements

¢ Next Monday, 4/27

= Table Views, Scroll Views and Presence 2

- Guest speaker: Jason Beaver, UIKit Engineer

Trang 4

Announcements

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

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

F ¬

Trang 6

Navigation Controllers

Trang 8

How It Fits Together

¢ Top view controller’s view

Trang 9

How It Fits Together

¢ Top view controller’s view

¢ Top view controller’s title

Trang 10

How It Fits Together

¢ Top view controller’s view

¢ Top view controller’s title

¢ Previous view controller's title

Trang 11

Modifying the Navigation Stack

¢ Push to add a view controller

- Cvoid)pushViewControLler: CUIViewControLller *)viewControLler

* 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];

b

Trang 13

In Response to User Actions

¢ Push from within a view controller on the stack

° Almost never call pop directly!

- Automatically invoked by the back button

Trang 14

Demo:

Pushing & Popping

Trang 15

Application Data Flow

Trang 17

A Controller for Each Screen

mm

Trang 18

Connecting View Controllers

¢ Multiple view controllers may need to share data

¢ One may need to know about what another is doing

= Watch for added, removed or edited data

- Other interesting events

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:

UllmagePickerController

Trang 22

Demo:

Passing Data Along

Trang 23

Customizing Navigation

Trang 24

Customizing Navigation

¢ Buttons or custom controls

¢ Interact with the entire screen

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

= Displayed when view controller is on top of the stack

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

viewControLLer.titLle = @“DetatL”;

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

¢ Target + action (like a regular button)

Trang 29

Text Bar Button Item

Trang 30

System Bar Button Item

- (vo1id)viewDidLoad

{

UIBarButtonItem *addButton = [[UIBarButtonItem alloc]

1n1tW1thBarButtonSystemTtem: U[BarButtonSystemTtemAdd styLe:UTBarButtonTtemStyLeBordered

target: self action: @seLector(Cadd: ) ];

self navigationiItem.rightBarButtoniItem = addButton;

LaddButton release];

b

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

b

Trang 32

Custom Title View

¢ Arbitrary view in place of the title

Trang 33

Back Button

¢ Sometimes a shorter back button is needed

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

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;

[heyButton release];

Trang 35

Demo:

Customizing Buttons

Trang 36

Tab Bar Controllers

Trang 38

How It Fits Together

Carrier ¢ Selected view controller’s view

Trang 39

How It Fits Together

¢ Selected view controller’s view

"7 ¢ All view controllers’ titles

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

H9 |0 c?000(210 1)

- Title + image or system item

° Each view controller comes with a tab bar item for customizing

Trang 42

Creating Tab Bar Items

¢ Title and image

Trang 43

Creating Tab Bar Items

Trang 44

Demo:

Using a Tab Bar Controller

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?

displayed automatically

- User can navigate to Most Recent

remaining view controllers W Top Rated

C History

.>x 9302 mài we TT

Featured Most Viewed Bookmarks Search More

Trang 47

More View Controllers

¢ What happens when a tab bar controller has too many

view controllers to display at once?

displayed automatically

- User can navigate to

remaining view controllers na eare

= Customize order + ©

Most Recent Top Rated History

>„Š vô Ô.~

Search Featured Most Viewed Bookmarks More

Trang 48

Combining Approaches

Trang 49

Tab Bar + Navigation Controllers

Multiple parallel hierarchies

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

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

Fulfillingness' First Fi

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, anotherNavControlLer, someViewControLLer, aye

Trang 52

Questions?

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

w