您的位置:首页 > 移动开发 > IOS开发

多控制器管理

2016-05-31 22:40 337 查看
- (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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS