创建一个自定义代理

@class MJTgFooterView;

/**
1.协议名称: 控件类名 + Delegate
2.代理方法普遍都是@optional
3.
*/ @protocol MJTgFooterViewDelegate <NSObject>
@optional
//可实现的代理方法
- (void)tgFooterViewDidClickedLoadBtn:(MJTgFooterView *)tgFooterView;
@end

声明代理,外界可以进行调用(控件器)

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

通知代理

/**
* 点击"加载"按钮
*/
- (IBAction)loadBtnClick {
// 1.隐藏加载按钮
self.loadBtn.hidden = YES; // 2.显示"正在加载"
self.loadingView.hidden = NO; // 3.显示更多的数据
// GCD
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // 3.0s后执行block里面的代码
// 通知代理
if ([self.delegate respondsToSelector:@selector(tgFooterViewDidClickedLoadBtn:)]) {
[self.delegate tgFooterViewDidClickedLoadBtn:self];
} // 4.显示加载按钮
self.loadBtn.hidden = NO; // 5.隐藏"正在加载"
self.loadingView.hidden = YES;
});
}

使用代理(实现方法)controller

@interface MJViewController () <UITableViewDataSource, MJTgFooterViewDelegate>
    // 设置footerView
MJTgFooterView *footer = [MJTgFooterView footerView];
footer.delegate = self;
self.tableView.tableFooterView = footer;
#pragma mark - MJTgFooterViewDelegate方法
/**
* 加载更多的数据
*/
- (void)tgFooterViewDidClickedLoadBtn:(MJTgFooterView *)tgFooterView
{
#warning 正常开发:发送网络请求给远程的服务器
// 1.添加更多的模型数据
MJTg *tg = [[MJTg alloc] init];
tg.icon = @"ad_01";
tg.title = @"新增加的团购数据..";
tg.price = @"";
tg.buyCount = @"";
[self.tgs addObject:tg]; // 2.刷新表格(告诉tableView重新加载模型数据, 调用tableView的reloadData)
[self.tableView reloadData];
}

IOS 自定义代理delegate方法的更多相关文章

  1. iOS基础 - UITableView的数据源(dataSource)和代理(delegate)

    UITableView的数据源(dataSource)和代理(delegate) UITableView需要一个数据源(dataSource)来显示数据,UITableView会向数据源查询一共有多少 ...

  2. iOS里面消除使用代理调用方法时间警告问题

    iOS里面有三种调用函数的方式: 直接调用方法   [对象名 方法]; performselector:    [对象名 perform方法]; NSInvocation     调用 在使用代理调用 ...

  3. IOS 如何选择delegate、notification、KVO?(转)

    前面分别讲了delegate.notification和KVO的实现原理,以及实际使用步骤,我们心中不禁有个疑问,他们的功能比较类似,那么在实际的编程中,如何选择这些方式呢? 在网上看到一个博客上详细 ...

  4. IOS 如何选择delegate、notification、KVO?

    IOS 如何选择delegate.notification.KVO? 博客分类: IOS   前面分别讲了delegate.notification和KVO的实现原理,以及实际使用步骤,我们心中不禁有 ...

  5. 代理delegate、NSNotification、KVO在开发中的抉择

    在开发ios应用的时候,我们会经常遇到一个常见的问题:在不过分耦合的前提下,controllers间怎么进行通信.在IOS应用不断的出现三种模式来实现这种通信: 1.委托delegation: 2.通 ...

  6. IOS设计模式--代理 (委托)

    原文 http://blog.csdn.net/lovefqing/article/details/8270111 委托(delegate)也叫代理是iOS开发中常用的设计模式.我们借助于protoc ...

  7. iOS 自定义转场动画

    代码地址如下:http://www.demodashi.com/demo/12955.html 一.总效果 本文记录分享下自定义转场动画的实现方法,具体到动画效果:新浪微博图集浏览转场效果.手势过渡动 ...

  8. iOS 自定义转场动画浅谈

    代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...

  9. 【iOS自定义键盘及键盘切换】详解

    [iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...

随机推荐

  1. 面向对象之-------------------永不停机的ATM

    import os class Account: def __init__(self, username, password, money=0): self.username = username s ...

  2. XtraFinder

    About System Integrity Protection in OS X 10.11 Apple's article . System Integrity Protection blocks ...

  3. arraylist和linkedlist内部的实现大致是怎样的

    1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机访问get和set,ArrayList优于LinkedList,因为ArrayList可以随 ...

  4. Web开发中FormData对象的使用

    参考: FormData 对象的使用 - Web API 接口 | MDN

  5. Linux执行.sh文件Permission denied

    执行sh文件报没有权限: 看下该文件的权限: 缺少执行的权限,直接加上吧: test.sh 权限加上去了,可以执行sh文件了 若用 chmod 4755 filename 可使此程序具有root的权限

  6. Mybatis学习笔记13 - 动态sql之set标签

    示例代码: 接口定义: package com.mybatis.dao; import com.mybatis.bean.Employee; public interface EmployeeMapp ...

  7. Linux的page cache使用情况/命中率查看和操控

    转载自宋宝华:https://blog.csdn.net/21cnbao/article/details/80458173 这里总结几个Linux文件缓存(page cache)使用情况.命中率查看的 ...

  8. Session有什么重大BUG,有什么方法可以解决

    [考点]ASP.NET中Session的多种保存方法.[出现频率]★★★☆☆[解答]使用进程内会话状态模式时,如果aspnet_wp.exe或应用程序域重新启动,则会话状态数据将丢失.可以用Sate ...

  9. array_map()关于回调函数的总结

    array_map()函数的第一个参数可以是匿名函数,系统函数,也可以是自己自定义的函!在全局空间下,这些函数的调用都很简单 在这里就不多说了!我们主要讨论的是该函数调用类中的方法和静态方法的区别 摘 ...

  10. Use Exception.ToString() instead of Exception.Message.

    Exception.Message contains only the message (doh) associated with the exception. Example: Object ref ...