{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 16 - Stanford CS193p Developing Applications for...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Stanford CS193p Fall 2011 Developing Applications for iOS Fall 2011 Stanford CS193p
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Stanford CS193p Fall 2011 Today NSTimer and “perform after delay” Two delayed-action alternatives. More View Animation Continuation of Kitchen Sink demo Alerts and Action Sheets Notifying the user and getting modal answers to questions. UIImagePickerController Getting images from the camera or photo library. Core Motion Measuring the device’s movement.
Image of page 2
Stanford CS193p Fall 2011 NSTimer Scheduled invocation of a method in the main queue NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:self selector:@selector(doSomething:) userInfo:(id)anyObject repeats:(BOOL)yesOrNo]; Not “real time” since it can run only each time around run loop Setting the time interval too short will essentially block the main thread. Taking too long each time you’re called could also essentially block the main thread. Do any time consuming stuff in a thread and just use the timer to update state quickly. Stopping the timer - (void)invalidate; You probably want to nil -out your pointers to the timer after this!
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Stanford CS193p Fall 2011 Perform after Delay Alternative to NSTimer NSObject method: - (void)performSelector:(SEL)aSelector withObject:(id)argument afterDelay:(NSTimeInterval)seconds; Executes on the run loop (if any) of the current thread Only call this on the main thread (other threads possible, but not straightforward). Not real time (just like NSTimer is not). Does not execute immediately, even if seconds is 0 (executes “very very soon” in that case). Can reschedule itself. Be careful that it stops calling itself when your view controller goes off screen, though. Example [self.tableView performSelector:@selector(reloadData) withObject:nil afterDelay:0]; Gives the UITableView a chance to “settle down” (by finishing this turn of the event loop).
Image of page 4
Stanford CS193p Fall 2011 Perform after Delay Canceling NSObject class method: + (void)cancelPreviousPerformRequestsWithTarget:(id)target selector:(SEL)aSelector object:(id)object; + (void)cancelPreviousPerformRequestsWithTarget:(id)target; There is no way to query what requests are outstanding At best, you can cancel and repost to be sure (but it will reset timing, of course).
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Stanford CS193p Fall 2011 Demo Kitchen Sink More sophisticated UIView animation NSTimer performSelector:withObject:afterDelay:
Image of page 6
Stanford CS193p Fall 2011 Alerts Two kinds of “pop up and ask the user something” mechanisms Action Sheets Alerts Action Sheets Slides up from the bottom of the screen on iPhone/iPod Touch, and in a popover on iPad. Can be displayed from a tab bar, toolbar, bar button item or from a rectangular area in a view. Usually asks questions that have more than two answers. Alerts Pop up in the middle of the screen. Usually ask questions with only two (or one) answers (e.g. OK/Cancel, Yes/No, etc.).
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern