[Lecture Notes] Stanford University Open class: IOS 7 App Development Lecture5

Source: Internet
Author: User
Tags access properties notification center

1.There is a class called Nsnotificationcenter. It has a class method called Defaultcenter.that returns a GKFX instance kind of like Nsuserdefault,standard Userdefault Did-a shared instance. That's the object you use to tune into radio stations. And you does it by sending it's this Message:addobserver selector name object. The first argument Observe,that Is,the object, wants to listen to the radio station. So in your controller-because controllers is the most common radio station Listeners-this would probably just being self . This was somewhere in your controller code. Selector is the method inside of the observer so you want to be called when something appears on the radio station. Some broadcast happens. Name is the name of the radio station. and sender There-object Sender-that's If you are want to listen to radio station broadcasts that come from a certain O Ther object. Often you pass nil here which means if anyone broadcasts on that Frequency,i want to hear it. (53:00)  2.so Another thing to understand are when you ' re-done listening,tune out. Sending a message to the notification center saying "removeobserver". And you can remove yourself as a observer of all radio station with the first one or you can just remove yourself from Li Stening to certain radio Stations,by specifying the name of the "the radio station and the" The sender is your don ' t want to list En to anymore. It's important to does this Because,unfortunately,the notification center keeps a pointer to your that's called "Unsafe Retai Ned. " So it's not strong or weak;it ' s unsafe retained. And what unsafe retained means is so if you go out of the heap without calling this First,the notification Center might Try and send you a notification and crash your app. (57:00)  3.uitextview:like uilabel,but Multi-line,selectable/edita Bel,scrollable,etc. Set its text and attributes via its nsmutableattributedstring.obtain the nsmutableattributedstring representing the text I n the Uitextview using ... @property (nonatomic,readonly) nstextstorage *textstorage; Nstextstorage is a subclass of nsmutableattributedstring. 4.The start of the lifecycle is creation. MVCs is most often instantiated out of a storyboard. What then? Outlet setting-appearing and Disappearing-geometry changes-low-memory situations. 5.After instantiation and Outlet-setting,viewdidload is called. This was an exceptionally good place-to-put a lot of setup code. But being careful because the geometry of your view is not set yet! At this point,you can ' t is sure you ' re on the IPhone 5-sized screen or an iPad or??? So does not initialize things is geometry-dependent here. 6.Just before the view appears on Screen,you Get notified (argument was Just whether you were appearing instantly or over Tim e via animation) -(void) Viewwillappear: (BOOL) animated;Your view would only get "loaded" once,but it might appear and disappear a lot. So don ' t put something in this method, that really wants to is in viewdidload.otherwise,you might is doing something over a nd over unnecessarily. Do something this if things you display was changing while your MVC is off-screen. View ' s geometry is set here,but there be other (better?) Places to react to Geometry. 7.and you get notified when you'll disappear off screen too. This is where you put the "remember what's going on" and cleanup code.
-(void) viewwilldisappear: (BOOL) animated{     [Super viewwilldisappear:animated]; // call   Superin all the Viewwill/did: Methods/Let's be friendly to theuser and remember the scroll Position they wereat[self rememberscrollposition]; // Do some the other clean up now so we ve been removed from screen [self savedatatopermanentstore]; // But being careful not to do anything time-consuming here,or appwould be sluggish}
There is "did" versions of both of the appearance methods
-(void) viewdidappear: (BOOL) animated; -(void) Viewdiddisappear: (BOOL) animated;
8.In low-memory situations,didreceivememorywaring gets called ... Anything "big" that can is recreated should probably is released (i.e. set strong pointer to nil). 9.notifications:the "Radio station" from the MVC slides. Nsnotificationcenter:get the default "Notification Center" Via[nsnotificationcenter Defaultcenter]then Send it the Following message if you want to "listen-a radio station":
-(void) Addobserver: (ID) Observer//You (the object to get notified)selector: (SEL) Methodtoinvokeifsomethinghappensname: (NSString*) name//Name of station (a constant somewhere)Object:(ID) sender;//whose changes you ' re instertsted in (Nil is anyone ' s)//you 'll then being notified when there is broadcasts-(void) Methodtoinvokeifsomethinghappens: (Nsnotification *) notification{Notification.name//The name passed aboveNotification.Object //The object sending you the notificationNotification.userinfo//notification-specific Information about what happened} 

10.Be sure to ' tune out ' when done listening[center removeobserver:self];or [Center removeobserver:self name: Uicontentsizecategorydidchangenotification Object:nil]; Failure to remove yourself can sometimes result in crashers. This is because the nsnotificationcenter keeps a "unsafe retained" pointer to you. A good place to remove yourself was when your MVC ' s View goes off. Or you can remove yourself in a method called Dealloc (called If you leave the heap)-(void) dealloc{//be careful in t His method!can ' t access properties!you is almost gone from heap/[[Nsnotificationcenter Defaultcenter]removeobserver: Self];}

[Lecture Notes] Stanford University Open class: IOS 7 App Development Lecture5

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.