[A gull's training note] [Objective-c] [Next day] [Personal notes]

Source: Internet
Author: User



Today I learned several ways to pass the value ... Just sticking to the notes from the class.


    • I don't know what it's called. Use variables to pass values




  FirstViewController *firstVC = [[FirstViewController alloc] init];

    firstVC.str = _textField.text;

    [self.navigationController pushViewController:firstVC animated:YES];




    • Single-case pass-through value
//SingleTon.m

static SingleTon * ton = nil;

+ (SingleTon *) shareTon {
If (ton == nil) {
         ton = [[SingleTon alloc] init];
     }
     return ton;
}

 

// write value

     SingleTon * ton = [SingleTon shareTon];
     ton.str = _textField.text;

 

// read value

SingleTon * ton = [SingleTon shareTon];
_Label.text = ton.str;




    • Notification Pass Value
// Create a notification The name of the notification is name, and the content sent is a dictionary type

NSNotification * note = [[NSNotification alloc] initWithName: @ "name" object: self userInfo: [NSDictionary dictionaryWithObject: _textField.text forKey: @ "key"]];

// Send notification
[[NSNotificationCenter defaultCenter] postNotification: note];

// Receive notification Receive notification, execute (note :) function The name of the notification is name
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (note :) name: @ "name" object: nil];

// Process notification
-(void) note: (NSNotification *) note {
     NSLog (@ "% @", [note.userInfo objectForKey: @ "key"]);
} 





[A gull's training note] [Objective-c] [Next day] [Personal notes]


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.