//聯(lián)系人:石虎QQ: 1224614774昵稱:嗡嘛呢叭咪哄
/**
注意點:?
1.看 GIF 效果圖.
2.看連線視圖的效果圖.
3.看實現代碼(直接賦值實現效果).
*/
一斋否、GIF 效果圖:
二、連線視圖的效果圖:
圖1:
圖2:
三签杈、實現代碼:
=========================
===================================================
==========================
控制器1:
//? ViewController.m
//通知測試dome
//
//? Created by石虎on 2017/7/22.
//? Copyright ? 2017年shihu. All rights reserved.
//
#import"ViewController.h"
#import"SHTwoViewController.h"
@interfaceViewController()
//顯示傳值的內容
@property(weak,nonatomic)IBOutletUILabel*textStrng;
//跳轉
- (IBAction)notificationClick:(UIButton*)sender;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//注冊通知----第一部
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(showLabelText:)name:@"labelTextNotification"object:nil];
}
//實現通知監(jiān)聽---第二部
- (void)showLabelText:(NSNotification*)notification
{
//第三,實現通知中心內部的方法,并實現傳值
idtext = notification.object;
//賦值到文本上面
self.textStrng.text= text;
}
//釋放通知---第四部
- (void)dealloc
{
//第四步,消息發(fā)送完,要移除掉
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@"labelTextNotification"object:nil];
}
#pragma mark -//點擊通知跳轉
- (IBAction)notificationClick:(UIButton*)sender{
SHTwoViewController*twoVC =[[SHTwoViewControlleralloc]init];
[selfpresentViewController:twoVCanimated:YEScompletion:nil];;
}
@end
=========================
===================================================
==========================
控制器2:
/? SHTwoViewController.m
//通知測試dome
//
//? Created by石虎on 2017/7/22.
//? Copyright ? 2017年shihu. All rights reserved.
//
#import"SHTwoViewController.h"
#import"ViewController.h"
@interfaceSHTwoViewController()
//輸入要傳值的文字
@property(weak,nonatomic)IBOutletUITextField*TextField;
//開始傳值
- (IBAction)startValue:(id)sender;
@end
@implementationSHTwoViewController
- (void)viewDidLoad {
[superviewDidLoad];
}
//開始傳值
- (IBAction)startValue:(id)sender
{
//發(fā)布通知----第三部
[[NSNotificationCenterdefaultCenter]postNotificationName:@"labelTextNotification"object:self.TextField.text];
[selfdismissViewControllerAnimated:YEScompletion:nil];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event {
[self.viewendEditing:YES];
}
@end
謝謝!!!