代理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;
    }
}

 

posted on 2015-07-06 10:01  彪biao  阅读(182)  评论(0编辑  收藏  举报

导航