通知,delegate,归档

通知:

发起通知:

 [[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;

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值