欢迎使用CSDN-markdown编辑器

来源:互联网 发布:电脑版淘宝怎么找微淘 编辑:程序博客网 时间:2024/05/17 01:13

IOS - Protocol的用法

1、创建Protocol:
1)创建protocol的.h文件
create new file->Object C file -> file type = protocol
声明方法
2)A viewController中声明protocol,B viewController中实现protocol方法
A.h中:
声明protocol:
@ protocol RefreshDelegate
-(void)refreshViewData;
@end
属性:@property (nonatomic, assign) id delegate;

2、继承Protocol
B.h中继承protocol
B

A.RefreshDelegate = self;
[self refreshViewData];

3、B.m中实现protocol方法:
-(void)refreshViewData{
[self reloadTableViewDataSource];
[self loadData];
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:1.0];
}

0 0
原创粉丝点击