判断代理是否实现了协议方法

1 // 3.1 判断代理是否实现了协议方法
2     if ([self.delegate respondsToSelector:@selector(tgFooterViewDidDownloadButtonClick:)]) {
3         [self.delegate tgFooterViewDidDownloadButtonClick:self];
4     }

 

// 代理如果使用强引用,就会产生循环引用,造成控制器和子视图都无法被释放,造成内存泄露

@property (nonatomic, weak) id <HMTgFooterViewDelegate> delegate;

 

 1 - (void)tgFooterViewDidDownloadButtonClick:(HMTgFooterView *)footerView
 2 {
 3     // 模拟取网络上获取数据加载数据
 4     NSLog(@"努力加载数据中....");
 5     
 6     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
 7         // 获得网络数据之后执行的操作
 8         
 9         // 向数组中添加数据,模拟网络加载完成之后的效果
10         NSDictionary *dict = @{@"title": @"哈哈", @"icon": @"ad_00", @"price": @"100.2", @"buyCount": @"250"};
11         HMTg *tg = [HMTg tgWithDict:dict];
12         
13         NSLog(@"加数据前 %lu", (unsigned long)self.tgs.count);
14         
15         [self.tgs addObject:tg];
16         
17         NSLog(@"加数据后 %lu", (unsigned long)self.tgs.count);
18         // 刷新数据
19         //    [self.tableView reloadData];
20         // 新建一个indexPath
21         NSIndexPath *path = [NSIndexPath indexPathForRow:(self.tgs.count - 1) inSection:0];
22         [self.tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationMiddle];
23         
24         // 通知页脚视图调整视图显示状态
25         [footerView endRefresh];
26     });
27     
28 }

 

posted @ 2015-04-10 15:54  liqiantu  阅读(868)  评论(0编辑  收藏  举报