block的使用规范:

来源:互联网 发布:淘宝大学vip课程 编辑:程序博客网 时间:2024/05/22 01:37

block的使用规范:

1 : 按之前的规定一个属性变量名  这样方便使用;

2 : 之后写一个@proterty;

3:写一个方法.H 方便对block的使用,另外在.M里面要实现这个方法;

typedef void(^clickedImageCallback)(TableViewCell* cell,NSInteger imageIndex);


@interface TableViewCell : UITableViewCell

@property (nonatomic,assign) BOOL displaysAsynchronously;//是否异步绘制
@property (nonatomic,strong) CellLayout* cellLayout;
@property (nonatomic,strong) NSIndexPath* indexPath;
@property (nonatomic ,copy)clickedImageCallback imageCallback;
//@property (nonatomic,copy) void(^clickedImageCallback)(TableViewCell* cell,NSInteger imageIndex);
@property (nonatomic,copy) void(^clickedLikeButtonCallback)(TableViewCell* cell,BOOL isLike);
@property (nonatomic,copy) void(^clickedAvatarCallback)(TableViewCell* cell);
@property (nonatomic,copy) void(^clickedReCommentCallback)(TableViewCell* cell,CommentModel* model);
@property (nonatomic,copy) void(^clickedCommentButtonCallback)(TableViewCell* cell);
@property (nonatomic,copy) void(^clickedOpenCellCallback)(TableViewCell* cell);
@property (nonatomic,copy) void(^clickedCloseCellCallback)(TableViewCell* cell);
- (void)getValue:(clickedImageCallback)imageCallback;

- (void)getValue:(clickedImageCallback)imageCallback {
    self.imageCallback = imageCallback;
}


1 存blcok数据的时间 直接存    这个是存数据的时间
            if (self.imageCallback) {
                self.imageCallback(self,tag);
            }

2 在调用的时间直接用这个方法直接对数据进行使用;

   //这个是用的时间
    [cell getValue:^(TableViewCell *cell, NSInteger imageIndex) {
        __strong typeof(weakSelf) sself = weakSelf;
        [sself tableViewCell:cell showImageBrowserWithImageIndex:imageIndex];
    }];

0 0
原创粉丝点击