-(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];
}
}
通知
- 第一個(gè)頁(yè)面
- 1.注冊(cè)通知
[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(justDoIt:) name:@"changeLabel" object:nil];
* 2.拿到暗號(hào),做事情(changeLabel為暗號(hào))
```
-(void)justDoIt:(NSNotification *)obj{
NSDictionary *dic = [obj object];
_notificationOrigionLabel.text = dic[@"boom"];
}```
- 第二個(gè)頁(yè)面
- 1:對(duì)暗號(hào)
- 在button里寫(xiě)
NSDictionary * dic = @{@"boom":@"??"};
[[NSNotificationCenter defaultCenter] postNotificationName:@"zhadan" object:dic];
* changeLabel為暗號(hào)
委托
@protocol BuyIphone6sDelegate <NSObject>
-(void)buyIphone:(NSString *)str;
@property(nonatomic,strong)id<BuyIphone6sDelegate>delegate;
- 【第二個(gè)頁(yè)面】
- 1在第二個(gè)頁(yè)面寫(xiě)協(xié)議辩恼,寫(xiě)在interface 上面
@protocol BuyIphone6sDelegate <NSObject>
- 2.在第二個(gè)頁(yè)面 實(shí)例化協(xié)議的變量
-(void)buyIphone:(NSString *)str;
- 3.讓協(xié)議變量去做做協(xié)議中的方法
@property(nonatomic,strong)id<BuyIphone6sDelegate>delegate;
- 在button里實(shí)現(xiàn)
UIAlertAction *enter = [UIAlertAction actionWithTitle:@"委托" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[_delegate buyIphone:@"??"];
}];
- 方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
// 委托
[_delegate buyIphone:@"??"];
- 【第一個(gè)頁(yè)面】
- 1.跳轉(zhuǎn)頁(yè)面的時(shí)候凯楔,簽合同。
vc2.delegate = self; self為vc1
- 2.在interface中實(shí)現(xiàn)這個(gè)協(xié)議
@interface DPNViewController ()<BuyIphone6sDelegate>
- 3.在.m中實(shí)現(xiàn)協(xié)議方法
-(void)buyIphone:(NSString *)str{
_delegateOriginLabel.text = str;
}