通知:
发起通知:
[[NSNotificationCenterdefaultCenter] postNotificationName:@"test"object:xxx]; xxx为要传的参数;
//接收通知
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(clicked:)name:@"test"object:nil];
接受通知后的方法:
- (void)Received:(NSNotification*) notification
{
str = (id)[notificationobject];//接受到的值
NSLog(@"yyyyy%@",str);
}
delegate :
第一页面。h页面
#import "xxxView.h"
@protocol Delegate <NSObject>
//代理方法
-(void)setCellWithCellTag:(NSString * )time;
@end
@interface xxxView :UiView
@property(nonatomic,weak)id<Delegate>delegate;
。m页面里面
哪里要执行该事件就写哪里。eg:view上的btn的点击事件
【self.delegate setCellWithCellTag:参数】
第二页面:
#import "xxx2viewcontroller.h"
@interface xxxController ()<Delegate> //遵守协议
xxx1ViewController * a1 = [[xxx1ViewControlleralloc]init];
a1.delegate =self;
//实现方法 去执行view上按钮要做的事情跳转页面等
-(void)setCellWithCellTag:(NSString * )time
{
//写内容
NSLog(@"******时间是是*******:%@",time);
}
归档:
model:一个类
@interface jsonModel : NSObject<NSCoding>//遵守协议
// 归档
- (void)saveList;
// 解档
+ (instancetype)returnList;
m文件中
#import "MJExtension.h"//可用mj哥的框架
@implementation JieshouModel
MJCodingImplementation
- (void)saveList{
//归档
[NSKeyedArchiverarchiveRootObject:selftoFile:[NSStringstringWithFormat:@"%@/Documents/Cache/jieshoulist",NSHomeDirectory()]];
}
+ (instancetype)returnList{
//解档
JieshouModel *obj = [NSKeyedUnarchiverunarchiveObjectWithFile:[NSStringstringWithFormat:@"%@/Documents/Cache/jieshoulist",NSHomeDirectory()]];
return obj;
}