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