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