71
CS193P - Lecture 12 iPhone Application Development Text Input Presenting Content Modally

Standford CS 193P: 12-Text Input Present Modal

Embed Size (px)

Citation preview

Page 1: Standford CS 193P: 12-Text Input Present Modal

CS193P - Lecture 12

iPhone Application Development

Text InputPresenting Content Modally

Page 2: Standford CS 193P: 12-Text Input Present Modal

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

Page 3: Standford CS 193P: 12-Text Input Present Modal

Today’s Topics

• Notes & Errata

• Drawing Optimizations (continued from Tuesday)

• iPhone Keyboards

• Customizing Text Input

• Presenting Content Modally

Page 4: Standford CS 193P: 12-Text Input Present Modal

Notes & Errata

Page 5: Standford CS 193P: 12-Text Input Present Modal

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

Page 6: Standford CS 193P: 12-Text Input Present Modal

When To Call -init

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

• Seriously.

Page 7: Standford CS 193P: 12-Text Input Present Modal

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

Page 8: Standford CS 193P: 12-Text Input Present Modal

Drawing Optimizations(Continued from Tuesday)

Page 9: Standford CS 193P: 12-Text Input Present Modal

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

Page 10: Standford CS 193P: 12-Text Input Present Modal

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

Page 11: Standford CS 193P: 12-Text Input Present Modal

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

Page 12: Standford CS 193P: 12-Text Input Present Modal

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

}

Page 14: Standford CS 193P: 12-Text Input Present Modal

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

Page 15: Standford CS 193P: 12-Text Input Present Modal

iPhone Keyboards

Page 16: Standford CS 193P: 12-Text Input Present Modal

Virtual keyboard

Appears when needed

Page 17: Standford CS 193P: 12-Text Input Present Modal

Virtual keyboard

Appears when needed

Page 18: Standford CS 193P: 12-Text Input Present Modal
Page 19: Standford CS 193P: 12-Text Input Present Modal

Portrait and Landscape

Page 20: Standford CS 193P: 12-Text Input Present Modal

Simple selection model

Text loupe/magnifier

Page 21: Standford CS 193P: 12-Text Input Present Modal

Many keyboard types

Adapted to task

Page 22: Standford CS 193P: 12-Text Input Present Modal

Many keyboard types

Adapted to task

Page 23: Standford CS 193P: 12-Text Input Present Modal

Many keyboard types

Adapted to task

Page 24: Standford CS 193P: 12-Text Input Present Modal

Many keyboard types

Adapted to task

Page 25: Standford CS 193P: 12-Text Input Present Modal

Many keyboard types

Adapted to task

Page 26: Standford CS 193P: 12-Text Input Present Modal

Many keyboard types

Adapted to task

Page 27: Standford CS 193P: 12-Text Input Present Modal

Single line editing

Page 28: Standford CS 193P: 12-Text Input Present Modal

Multi-line editing

Page 29: Standford CS 193P: 12-Text Input Present Modal

20Languages

Full dictionary support

Page 30: Standford CS 193P: 12-Text Input Present Modal

English

Page 31: Standford CS 193P: 12-Text Input Present Modal

French

Page 32: Standford CS 193P: 12-Text Input Present Modal

Russian

Page 33: Standford CS 193P: 12-Text Input Present Modal

Korean

Page 34: Standford CS 193P: 12-Text Input Present Modal

Japanese Romaji

Page 35: Standford CS 193P: 12-Text Input Present Modal

Japanese Kana

Page 36: Standford CS 193P: 12-Text Input Present Modal

Chinese Pinyin

Page 37: Standford CS 193P: 12-Text Input Present Modal

Chinese Handwriting

Simplified

Traditional

Page 38: Standford CS 193P: 12-Text Input Present Modal

Customizing Text Input

Page 39: Standford CS 193P: 12-Text Input Present Modal

Text Containers

Page 40: Standford CS 193P: 12-Text Input Present Modal

Text Containers

Delegates

Notifications

Methods

Page 41: Standford CS 193P: 12-Text Input Present Modal

Text Containers

Text Input Traits

Page 42: Standford CS 193P: 12-Text Input Present Modal

Text Input Traits

Protocol

UITextField

UITextView

Page 43: Standford CS 193P: 12-Text Input Present Modal

Text Input Traits

Autocapitalization

Autocorrection

Keyboard Type

Keyboard Appearance

Return Key Type

Return Key Autoenabling

Secure Text Entry

Page 44: Standford CS 193P: 12-Text Input Present Modal

URL Keyboard

Go button

Text Input Traits

Page 45: Standford CS 193P: 12-Text Input Present Modal

Default Keyboard

Google button

Text Input Traits

Page 46: Standford CS 193P: 12-Text Input Present Modal

Text Containers

Text Input Traits

Delegates

Notifications

Methods

Page 47: Standford CS 193P: 12-Text Input Present Modal

Text Containers

Page 48: Standford CS 193P: 12-Text Input Present Modal

UITextField

Design time

Page 49: Standford CS 193P: 12-Text Input Present Modal

Design time

URL Keyboard

Go button

UITextField

Page 50: Standford CS 193P: 12-Text Input Present Modal

Run time

URL Keyboard

Go button

UITextField

Page 51: Standford CS 193P: 12-Text Input Present Modal

Become first responder

URL Keyboard

Go button

UITextField

Page 52: Standford CS 193P: 12-Text Input Present Modal

Keyboard

Become first responder

URL Keyboard

Go button

UITextField

Page 53: Standford CS 193P: 12-Text Input Present Modal

Keyboard

Keyboard adopts traits

URL Keyboard

Go button

UITextField

URL Keyboard

Go button

Page 54: Standford CS 193P: 12-Text Input Present Modal

Text Containers

UITextField

UITextView

Web Forms

Page 55: Standford CS 193P: 12-Text Input Present Modal

Demo:Text Input

Page 56: Standford CS 193P: 12-Text Input Present Modal

Presenting Content Modally

Page 57: Standford CS 193P: 12-Text Input Present Modal

• For adding or picking data

Presenting Content Modally

Page 58: Standford CS 193P: 12-Text Input Present Modal

Presenting// Recipe list view controller

- (void)showAddRecipe {

RecipeAddViewController *viewController = ...;

[self presentModalViewController:viewController animated:YES];

}

Page 59: Standford CS 193P: 12-Text Input Present Modal

Presenting// Recipe list view controller

- (void)showAddRecipe {

RecipeAddViewController *viewController = ...;

[self presentModalViewController:viewController animated:YES];

}

Page 60: Standford CS 193P: 12-Text Input Present Modal

Dismissing// Recipe list view controller

- (void)didAddRecipe {

[self dismissModalViewControllerAnimated:YES];

}

Page 61: Standford CS 193P: 12-Text Input Present Modal

Dismissing// Recipe list view controller

- (void)didAddRecipe {

[self dismissModalViewControllerAnimated:YES];

}

Page 62: Standford CS 193P: 12-Text Input Present Modal

Separate Navigation Stacks

Page 63: Standford CS 193P: 12-Text Input Present Modal

Separate Navigation Stacks

Page 64: Standford CS 193P: 12-Text Input Present Modal

Separate Navigation Stacks

Page 65: Standford CS 193P: 12-Text Input Present Modal

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

Page 66: Standford CS 193P: 12-Text Input Present Modal

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!

Page 67: Standford CS 193P: 12-Text Input Present Modal

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

Page 68: Standford CS 193P: 12-Text Input Present Modal

Presence - Part 3

Page 69: Standford CS 193P: 12-Text Input Present Modal

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

Page 70: Standford CS 193P: 12-Text Input Present Modal

Demo:Presence 3

Page 71: Standford CS 193P: 12-Text Input Present Modal

Questions?