• 代理demo


    1-  .h

    #import <UIKit/UIKit.h>
    
    typedef enum {
        HMStatusDetailTopToolbarButtonTypeRetweeted,
        HMStatusDetailTopToolbarButtonTypeComment,
    } HMStatusDetailTopToolbarButtonType;
    
    @class HMStatusDetailTopToolbar, HMStatus;
    
    @protocol HMStatusDetailTopToolbarDelegate <NSObject>
    //代理方法
    @optional
    - (void)topToolbar:(HMStatusDetailTopToolbar *)topToolbar didSelectedButton:(HMStatusDetailTopToolbarButtonType)buttonType;
    @end
    
    @interface HMStatusDetailTopToolbar : UIView
    + (instancetype)toolbar;
    
    @property (nonatomic, weak) id<HMStatusDetailTopToolbarDelegate> delegate;
    @property (nonatomic, assign) HMStatus *status;
    
    @property (nonatomic, assign) HMStatusDetailTopToolbarButtonType selectedButtonType;
    @end

    .m

        // 3.通知代理
        if ([self.delegate respondsToSelector:@selector(topToolbar:didSelectedButton:)]) {
            [self.delegate topToolbar:self didSelectedButton:button.tag];
        }

     实现代理方法:

    #pragma mark - 顶部工具条的代理
    - (void)topToolbar:(HMStatusDetailTopToolbar *)topToolbar didSelectedButton:(HMStatusDetailTopToolbarButtonType)buttonType
    {
        [self.tableView reloadData];
        switch (buttonType) {
            case HMStatusDetailTopToolbarButtonTypeComment: // 评论
                [self loadComments];
                break;
                
            case HMStatusDetailTopToolbarButtonTypeRetweeted: // 转发
                [self loadRetweeteds];
                break;
        }
    }
    IOS开发
  • 相关阅读:
    mysql外键添加error1215
    shell命令获取最新文件的名称
    centos7 apache提供文件下载
    centos7 时间设置
    微服务通信的类型
    angular-cli
    npm
    模块相关
    加油!冲冲冲
    软件评测
  • 原文地址:https://www.cnblogs.com/luanmage/p/4623588.html
Copyright © 2020-2023  润新知