standford cs 193p: 12-text input present modal

Post on 10-Apr-2015

1.588 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CS193P - Lecture 12

iPhone Application Development

Text InputPresenting Content Modally

Announcements

• Presence 3 assignment out today, due Wednesday 11/5

• Enrolled students can (still) pick up an iPod Touch after class

• Final project proposals due on Monday 1/1

Today’s Topics

• Notes & Errata

• Drawing Optimizations (continued from Tuesday)

• iPhone Keyboards

• Customizing Text Input

• Presenting Content Modally

Notes & Errata

Using UINavigationController

• Don’t add a child view controller’s view manually

• Push a view controller to display it

UIViewController *viewController = ...;

[navigationController.view addSubview:viewController.view];

UIViewController *viewController = ...;

[navigationController pushViewController:viewController

! animated:YES];

When To Call -init

• Call -init (or variants thereof ) only once on an object. Ever.

• Seriously.

Operations and Autorelease Pools

• If you detach a thread using NSThread, you need to create your own autorelease pool...

• With NSOperation and NSOperationQueue, it’s done for you

Drawing Optimizations(Continued from Tuesday)

Draw Lazily

• Never call -drawRect: directly

• Invoke -setNeedsDisplay! Or even better, -setNeedsDisplayInRect:

• In your -drawRect: implementation, only do the work required for the specified rect

Compose with Image Views

• When drawing large images on the screen, don’t use a custom view with an override of -drawRect:

• UIImageView has built-in optimizations for speed and memory! Memory mapping reduces your footprint

! Doesn’t copy image data to draw

Avoid Transparency When Possible

• Opaque views are much faster to draw than transparent views

• Especially important when scrolling

• This is the default- introduce transparency with care

Reusing Table View Cells

• Memory churn can affect smoothness of scrolling

• UITableView provides mechanism for reusing table view cells

- (UITableViewCell *)tableView:(UITableView *)tableView

cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

return cell;

}

// Ask the table view if it has a cell we can reuse

UITableViewCell *cell =

[tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (!cell) { // If not, create one with our identifier

cell = [[UITableViewCell alloc] initWithFrame:CGRectZero

identifier:MyIdentifier];

[cell autorelease];

}

Performance Recap

• Performance is both an art and a science! Combine tools & concrete data with intuition & best practices

• Be frugal with memory

• Concurrency is tricky, abstract it if possible

• Drawing is expensive, avoid unnecessary work

iPhone Keyboards

Virtual keyboard

Appears when needed

Virtual keyboard

Appears when needed

Portrait and Landscape

Simple selection model

Text loupe/magnifier

Many keyboard types

Adapted to task

Many keyboard types

Adapted to task

Many keyboard types

Adapted to task

Many keyboard types

Adapted to task

Many keyboard types

Adapted to task

Many keyboard types

Adapted to task

Single line editing

Multi-line editing

20Languages

Full dictionary support

English

French

Russian

Korean

Japanese Romaji

Japanese Kana

Chinese Pinyin

Chinese Handwriting

Simplified

Traditional

Customizing Text Input

Text Containers

Text Containers

Delegates

Notifications

Methods

Text Containers

Text Input Traits

Text Input Traits

Protocol

UITextField

UITextView

Text Input Traits

Autocapitalization

Autocorrection

Keyboard Type

Keyboard Appearance

Return Key Type

Return Key Autoenabling

Secure Text Entry

URL Keyboard

Go button

Text Input Traits

Default Keyboard

Google button

Text Input Traits

Text Containers

Text Input Traits

Delegates

Notifications

Methods

Text Containers

UITextField

Design time

Design time

URL Keyboard

Go button

UITextField

Run time

URL Keyboard

Go button

UITextField

Become first responder

URL Keyboard

Go button

UITextField

Keyboard

Become first responder

URL Keyboard

Go button

UITextField

Keyboard

Keyboard adopts traits

URL Keyboard

Go button

UITextField

URL Keyboard

Go button

Text Containers

UITextField

UITextView

Web Forms

Demo:Text Input

Presenting Content Modally

• For adding or picking data

Presenting Content Modally

Presenting// Recipe list view controller

- (void)showAddRecipe {

RecipeAddViewController *viewController = ...;

[self presentModalViewController:viewController animated:YES];

}

Presenting// Recipe list view controller

- (void)showAddRecipe {

RecipeAddViewController *viewController = ...;

[self presentModalViewController:viewController animated:YES];

}

Dismissing// Recipe list view controller

- (void)didAddRecipe {

[self dismissModalViewControllerAnimated:YES];

}

Dismissing// Recipe list view controller

- (void)didAddRecipe {

[self dismissModalViewControllerAnimated:YES];

}

Separate Navigation Stacks

Separate Navigation Stacks

Separate Navigation Stacks

Dismissing Modally

• Who should do it?

• Best practice is for the same object to call present and dismiss

• Define delegate methods for the presented controller! Tell the delegate when the presented controller is done

! The delegate makes the call to dismiss

Parent Controller

Child Controller

Present

Dismissing Modally

• Who should do it?

• Best practice is for the same object to call present and dismiss

• Define delegate methods for the presented controller! Tell the delegate when the presented controller is done

! The delegate makes the call to dismiss

Parent Controller

Child Controller

I’m done!

Dismissing Modally

• Who should do it?

• Best practice is for the same object to call present and dismiss

• Define delegate methods for the presented controller! Tell the delegate when the presented controller is done

! The delegate makes the call to dismiss

Parent Controller

Child Controller

Dismiss

Presence - Part 3

Goals for Presence 3

• Avoid expensive work on the main thread! Use background threads to keep interface responsive

! Abstract thread lifecycle with NSOperation & NSOperationQueue

• Allow the user to update their own status! Text input with the keyboard

! Present a view controller modally

Demo:Presence 3

Questions?

top related