[英]How do I declare a block that returns a UIView?
I keep trying to create a block that will return a UIView after it fetches it from the background. 我一直在尝试创建一个块,它会在从后台获取UIView后返回它。 I got the fetch from the background part, but I am having trouble setting up the block. 我从后台部分获取了,但是我在设置块时遇到了问题。 This code works, but I want a block that can be called from another file. 此代码有效,但我想要一个可以从另一个文件调用的块。 Thanks in advance. 提前致谢。
I can't call launchAd for viewDidLoad, and nothing works. 我无法为viewDidLoad调用launchAd,也没有任何效果。
typedef void (^launchAd)(UIView *);
-(void)launchAd:(void (^)(UIView *ad))block
{
}
Probably you can try something like below: 可能你可以试试下面的东西:
//class file 1:
+ (void) doYourStuff:(void (^)(UIView* returnedView))successBlock {
successBlock(returnedView);
}
//class file 2:
[class1 doYourStuff:success:^(UIView* returnedView) {
//do whatever you want with the returned data
}];
If you want to add failure block to return failure scenarios: 如果要添加故障块以返回故障情形:
+ (void) doYourStuff:(void (^)(UIView* returnedView))successBlock
failure:(void (^)(NSError *error))failureBlock {
if (getView)
successBlock(returnedView);
else
failureBlock(error);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.