補充:(昨天晚上,我遇到一個問題,一直沒有解決,因而找本身的筆記,發現本身的筆記,很不全面,不少漏點;看到本身的筆記作成這樣,我感到很氣憤。回去的時候,我就想,本身必定要把這筆記作詳細,無論多簡單的,都要作一個完整的記錄、註釋,不要偷懶!)
時間:2015年07月07日
//—————————————————---------------------委託方--------------------------------------------------
// BViewController.h
// 星座運程App
#import <UIKit/UIKit.h>
@class BViewController;//聲明BViewController是一個類,由於在協議中要使用它,但它的定義還在協議的下面,所以就要預聲明
//一、定義協議
@protocol BViewControllerDelegate <NSObject>//繼承NSObject就能夠了
//第一個參數必定是委託方,這樣就好區分這個委託是誰的,而且可能還要用到它,這裏是BViewController這個類
- (void)returnStarInfo:(BViewController *)Bviewc andMssage:(NSString *)msg andTitle:(NSString *)title;
@end
@interface BViewController : UIViewController
//二、引用代理
@property(nonatomic,weak)id<BViewControllerDelegate>delegate;
@property(nonatomic,strong)NSDictionary *starDic;
@end
//三、發送消息
// BViewController.m
// 星座運程App
#import "BViewController.h"
//三、在一個適當的時機,發送消息
- (IBAction)returnStarInfo:(UIButton *)sender {
UIButton *bt=[[UIButton alloc]init];
bt=sender;
NSString *str=[self.starDic objectForKey:bt.titleLabel.text];
//當發生了點擊綁定動做的按鈕時,發送消息
[self.delegate returnStarInfo:self andMssage:str andTitle:bt.titleLabel.text];
[self.navigationController popViewControllerAnimated:YES];
}
//————————————————————--------------------------------代理方--------------------------------------------
// AViewController.m
// 星座運程App
#import "AViewController.h"
#import
「BViewController.h」//協議就存在這個文件中中
//一、遵照協議
@interface AViewController ()<BViewControllerDelegate>//
協議就存在這個文件中:BViewController.h
@end
//二、設置代理
- (IBAction)selectStar:(UIButton *)sender {
BViewController *bvc=[[BViewController alloc]initWithNibName:@"BViewController" bundle:nil];
bvc.delegate=self;//設置本身爲代理方
[self.navigationController pushViewController:bvc animated:YES];
}
//實現方法
-(void)returnStarInfo:(BViewController *)Bviewc andMssage:(NSString *)msg andTitle:(NSString *)title{
self.starInfo.text=msg;
self.title=[title stringByAppendingString:@" --- 12星座"];
}
//-------------------------------------------------------------------------------------------------------