Standford CS 193P: 12-Text Input Present Modal
-
Upload
oleksiy-kovyrin -
Category
Documents
-
view
1.588 -
download
4
Transcript of Standford CS 193P: 12-Text Input Present Modal
![Page 1: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/1.jpg)
CS193P - Lecture 12
iPhone Application Development
Text InputPresenting Content Modally
![Page 2: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/2.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/3.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/4.jpg)
Notes & Errata
![Page 5: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/5.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/7.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/8.jpg)
Drawing Optimizations(Continued from Tuesday)
![Page 9: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/9.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/10.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/12.jpg)
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 13: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/13.jpg)
More on Optimizing Drawing
• “iPhone Application Programming Guide - Drawing Tips”https://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/GraphicsandDrawing/chapter_6_section_3.html
![Page 14: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/14.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/15.jpg)
iPhone Keyboards
![Page 16: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/16.jpg)
Virtual keyboard
Appears when needed
![Page 17: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/17.jpg)
Virtual keyboard
Appears when needed
![Page 18: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/18.jpg)
![Page 19: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/19.jpg)
Portrait and Landscape
![Page 20: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/20.jpg)
Simple selection model
Text loupe/magnifier
![Page 21: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/21.jpg)
Many keyboard types
Adapted to task
![Page 22: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/22.jpg)
Many keyboard types
Adapted to task
![Page 23: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/23.jpg)
Many keyboard types
Adapted to task
![Page 24: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/24.jpg)
Many keyboard types
Adapted to task
![Page 25: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/25.jpg)
Many keyboard types
Adapted to task
![Page 26: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/26.jpg)
Many keyboard types
Adapted to task
![Page 27: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/27.jpg)
Single line editing
![Page 28: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/28.jpg)
Multi-line editing
![Page 29: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/29.jpg)
20Languages
Full dictionary support
![Page 30: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/30.jpg)
English
![Page 31: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/31.jpg)
French
![Page 32: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/32.jpg)
Russian
![Page 33: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/33.jpg)
Korean
![Page 34: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/34.jpg)
Japanese Romaji
![Page 35: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/35.jpg)
Japanese Kana
![Page 36: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/36.jpg)
Chinese Pinyin
![Page 37: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/37.jpg)
Chinese Handwriting
Simplified
Traditional
![Page 38: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/38.jpg)
Customizing Text Input
![Page 39: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/39.jpg)
Text Containers
![Page 40: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/40.jpg)
Text Containers
Delegates
Notifications
Methods
![Page 41: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/41.jpg)
Text Containers
Text Input Traits
![Page 42: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/42.jpg)
Text Input Traits
Protocol
UITextField
UITextView
![Page 43: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/43.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/44.jpg)
URL Keyboard
Go button
Text Input Traits
![Page 45: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/45.jpg)
Default Keyboard
Google button
Text Input Traits
![Page 46: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/46.jpg)
Text Containers
Text Input Traits
Delegates
Notifications
Methods
![Page 47: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/47.jpg)
Text Containers
![Page 48: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/48.jpg)
UITextField
Design time
![Page 49: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/49.jpg)
Design time
URL Keyboard
Go button
UITextField
![Page 50: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/50.jpg)
Run time
URL Keyboard
Go button
UITextField
![Page 51: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/51.jpg)
Become first responder
URL Keyboard
Go button
UITextField
![Page 52: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/52.jpg)
Keyboard
Become first responder
URL Keyboard
Go button
UITextField
![Page 53: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/53.jpg)
Keyboard
Keyboard adopts traits
URL Keyboard
Go button
UITextField
URL Keyboard
Go button
![Page 54: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/54.jpg)
Text Containers
UITextField
UITextView
Web Forms
![Page 55: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/55.jpg)
Demo:Text Input
![Page 56: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/56.jpg)
Presenting Content Modally
![Page 57: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/57.jpg)
• For adding or picking data
Presenting Content Modally
![Page 58: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/58.jpg)
Presenting// Recipe list view controller
- (void)showAddRecipe {
RecipeAddViewController *viewController = ...;
[self presentModalViewController:viewController animated:YES];
}
![Page 59: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/59.jpg)
Presenting// Recipe list view controller
- (void)showAddRecipe {
RecipeAddViewController *viewController = ...;
[self presentModalViewController:viewController animated:YES];
}
![Page 60: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/60.jpg)
Dismissing// Recipe list view controller
- (void)didAddRecipe {
[self dismissModalViewControllerAnimated:YES];
}
![Page 61: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/61.jpg)
Dismissing// Recipe list view controller
- (void)didAddRecipe {
[self dismissModalViewControllerAnimated:YES];
}
![Page 62: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/62.jpg)
Separate Navigation Stacks
![Page 63: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/63.jpg)
Separate Navigation Stacks
![Page 64: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/64.jpg)
Separate Navigation Stacks
![Page 65: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/65.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/66.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/67.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/68.jpg)
Presence - Part 3
![Page 69: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/69.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/70.jpg)
Demo:Presence 3
![Page 71: Standford CS 193P: 12-Text Input Present Modal](https://reader034.fdocuments.us/reader034/viewer/2022051413/55288cab550346eb6e8b48ed/html5/thumbnails/71.jpg)
Questions?