- (IBAction)back:(UIButton
*)sender
{
//通过展示控制器关闭当前窗口
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
{
//通过展示控制器关闭当前窗口
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
-(void)prepareForSegue:(UIStoryboardSegue
*)segue sender:(id)sender
{
NSLog(@"%@",segue.identifier);
if ([segue.identifier isEqualToString:@"modal"])
{
SecondViewController *second =segue.destinationViewController;
second.text = @"welcome to you";
{
NSLog(@"%@",segue.identifier);
if ([segue.identifier isEqualToString:@"modal"])
{
SecondViewController *second =segue.destinationViewController;
second.text = @"welcome to you";
}
}
//定义反向传数据的代理协议
@protocol SecondViewControllerDelegate
-(void)comeback:(NSString *)str;
@protocol SecondViewControllerDelegate
-(void)comeback:(NSString *)str;
@end
//定义协议
@property
(weak,nonatomic)id<SecondViewControllerDelegate>delegate;
//通过代理反向传数据
[self.delegate
comeback:@"Tom"];
UIViewController<SecondViewControllerDelegate>
second.delegate
=
self;
//成为消息的观察者
[[NSNotificationCenter
defaultCenter]addObserver:self
selector:@selector(comeback:)
name:SECONDVIEWCONTROLLERNOTIFICATION
object:nil];
//取消观察者
[[NSNotificationCenter
defaultCenter]removeObserver:self
name:SECONDVIEWCONTROLLERNOTIFICATION
object:nil];
//通过通知方式反向传数据
[[NSNotificationCenter
defaultCenter]postNotificationName:SECONDVIEWCONTROLLERNOTIFICATION
object:nil
userInfo:@{SECONDVIEWCONTROLLERNOTIFICATIONKey:@"Tom"}];
//从通知对象取出数据
NSDictionary
*data = notification.userInfo;
self.Label.text
= [data
objectForKey:SECONDVIEWCONTROLLERNOTIFICATIONKey];

被折叠的 条评论
为什么被折叠?



