代理
第一步:
@protocol SDCycleScrollViewDelegate <NSObject>
//@optional
/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index;
@end
第二步:
@property (nonatomic, weak) id<SDCycleScrollViewDelegate> delegate;
第三步:
if ([self.delegate respondsToSelector:@selector(cycleScrollView:didSelectItemAtIndex:)]) {
[self.delegate cycleScrollView:self didSelectItemAtIndex:indexPath.item % self.imagePathsGroup.count];
}
第四步:
<SDCycleScrollViewDelegate>
第五步:
_bannerView.delegate = self;
第六步:
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
//执行相应的方法
}
block
第一步:
@class LYUser;
typedef void (^LoginSuccessBlock)(LYUser *);
第二步:
/* 登录成功之后的回调闭包 */
@property (nonatomic, copy) LoginSuccessBlock block;
第三步:
if(self.block) {
self.block(user);
}
第四步:
LYLoginViewController *loginVc = [[LYLoginViewController alloc] init];
loginVc.block = ^(LYUser *user) {
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:user.avatar_url]]];
[weakSelf.headerView.iconButton setBackgroundImage:image forState:UIControlStateNormal];
weakSelf.headerView.nameLabel.text = user.nickname;
// 保存登录状态
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isLogin"];
[[NSUserDefaults standardUserDefaults] setObject:user.avatar_url forKey:@"avatar_url"];
[[NSUserDefaults standardUserDefaults] setObject:user.nickname forKey:@"nickname"];
[[NSUserDefaults standardUserDefaults] synchronize];
// 登录成功重新请求数据以及刷新视图
[weakSelf loadLikeLoad];
[weakSelf inspectStatus];
};
MRNavigationController *loginNav = [[MRNavigationController alloc] initWithRootViewController:loginVc];
[self.navigationController presentViewController:loginNav animated:YES completion:nil];
}
block2
第一步:
/** block方式监听点击 */
@property (nonatomic, copy) void (^clickItemOperationBlock)(NSInteger currentIndex);
第二步:
if (self.clickItemOperationBlock) {
self.clickItemOperationBlock(indexPath.item % self.imagePathsGroup.count);
}
第三步 :
ViewController2 *vc =[[ViewController2 alloc]init];
// 回调修改颜色
vc.clickItemOperationBlock = ^(NSInteger currentIndex){
//执行相应的方法
};
block3
@property (nonatomic, copy) void(^sureAndGetCodeActionBlock)(UIButton *sender);
if (self.sureAndGetCodeActionBlock) {
self.sureAndGetCodeActionBlock(sender);
}
self.bindView.sureAndGetCodeActionBlock = ^(UIButton *sender) {
}