程序员

委托与通知

2015-12-11  本文已影响266人  你瞅誰
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        // 委托
        [_delegate buyIphone:@"📱"];
    }else if (buttonIndex == 1){
    // 通知
        NSDictionary *dic = @{@"boom":@"💣"};
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeLabel" object:dic];
        
    }
}

通知

-(void)justDoIt:(NSNotification *)obj{
NSDictionary *dic = [obj object];
_notificationOrigionLabel.text = dic[@"boom"];
}```

 UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"通知" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [ac addAction:cancle];
        NSDictionary * dic = @{@"boom":@"💣"};
        [[NSNotificationCenter defaultCenter] postNotificationName:@"zhadan" object:dic];
 *   changeLabel为暗号  

委托

 UIAlertAction *enter = [UIAlertAction actionWithTitle:@"委托" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [_delegate buyIphone:@"📱"];
        }];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        // 委托
        [_delegate buyIphone:@"📱"];

vc2.delegate = self; self为vc1

-(void)buyIphone:(NSString *)str{
    
    _delegateOriginLabel.text = str;
}
上一篇下一篇

猜你喜欢

热点阅读