多控制器管理
- (IBAction)back:(UIButton *)sender
{
   
//通过展示控制器关闭当前窗口
    [
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";
    }
}
//定义反向传数据的代理协议
@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];
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Chris201604/article/details/51549883
文章标签: iOS
个人分类: iOS
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

多控制器管理

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭