草庐IT

iphone - 用 block 简化委托(delegate)方案——在这种情况下是否可能?

我已经阅读了很多关于使用block的正面信息-特别是它通过消除委托(delegate)调用来简化代码。我找到了在动画结束时使用block而不是委托(delegate)调用的示例-我了解如何完成。但我真的很想知道在呈现和关闭ViewController时必须使用委托(delegate)的繁琐方案是否也可以用block来简化。显示和关闭方案的标准推荐方式如下所示,其中在VC1中呈现了一个新的VC2,它在VC1中再次被代表关闭。VC2*vc2=[[VC2alloc]initWithNibName:@"VC2"bundle:nil];vc2.delegate=self;[selfpresent

iphone - 如何创建包装器以将 block 用于使用回调的类?

我正在深入研究iOS编程,并且正在学习如何使用block。我在我的项目中使用了一个糟糕的、过度设计的库,它使用一个回调方法来处理所有数据请求...@protocolSuckyClassDelegate-(void)returnedSuckyData:(NSMutableDictionary*)data;@end@interfaceSuckyClass:NSObject@property(nonatomic,weak)iddelegate;-(void)getSuckyData;@end@interfaceMyViewController:UIViewController-(void)r

ios - viewWillTransitionToSize 协调器忽略 block

尝试了新的旋转方法,我需要知道设备是否正在旋转,以便推迟和取消旋转时不需要的操作。-(void)viewWillTransitionToSize:(CGSize)sizewithTransitionCoordinator:(id)coordinator{[superviewWillTransitionToSize:sizewithTransitionCoordinator:coordinator];_rotating=YES;[coordinatornotifyWhenInteractionEndsUsingBlock:^(idcontext){_rotating=NO;}];}看起来

ios - 如何在 SDwebimage 中使用成功和失败 block

我有最新版本的SDWebimage但它没有成功和失败我尝试了以下方法,但SDwebimage没有方法[self.imageViewsetImageWithURL:[NSURLURLWithString:self.imageURL]placeholderImage:[UIImageimageNamed:@"YourPlaceholder.png"]success:^(UIImage*image){//removeanimation}failure:^(NSError*error){NSLog(@"thumbnailerror:%@",error);//handlefaileddownlo

ios - 理解 ios UIView 动画 block 和 dispatch_async(dispatch_get_main_queue) block

我正在尝试更好地理解这个主题。假设我想做一些非常酷的动画,如下所示-(void)coolAnimation{[UIViewanimateWithDuration:somedurationanimations:^{someanimation}];}既然它是一个动画block,它会自动添加到main_queue中吗?或者,为了获得最佳实践,我应该始终将UI更新添加到main_queue中,如下所示。dispatch_async(dispatch_get_main_queue(),^{[selfcoolAnimation];}); 最佳答案

ios - 如何在 Objective-C 中使用 enumerateByteRangesUsingBlock?

enumerateByteRangesUsingBlock:方法在NSData类中,在Apple文档中解释如下:Enumeratethrougheachrangeofbytesinthedataobjectusingablock.-(void)enumerateByteRangesUsingBlock:(void(^)(constvoid*bytes,NSRangebyteRange,BOOL*stop))blockParametersblockTheblocktoapplytobyterangesinthearray.Theblocktakesthreearguments:bytes

ios - 使用 block 将数据传回 View Controller

我在看thisquestion.其中一个答案显示了如何使用block向后传递数据查看prepareForSegue方法。我的理解是这种方法应该真正用于向前传递数据,而不是向后传递数据。我想为此目的尝试block-将数据传递回另一个viewController。我的问题是:如何在不使用prepareForSegue方法的情况下执行此操作?例如,我可以在UITableView中使用-didselectRowAtIndexPath并关闭View-但是接收View如何得到“通知”有数据返回,而不使用委托(delegate)? 最佳答案 向后

ios - 为什么在使用 Quick 进行单元测试时多次调用 before- 和 afterEach block ?

我用一些示例组编写了一个测试用例,包括beforeEach和afterEach。我希望每个beforeEach和afterEach都会为每个it调用一次。唉,对于单个it,beforeEach和afterEach被调用了多次。我查看了一些文档(即Quick自己的文档和http://jasmine.github.io/2.1/introduction.html),但这些对我的事业没有帮助。这是一个演示这一点的小片段:类CheckerTests:QuickSpec{overridefuncspec(){describe("something"){beforeEach{tLog.info("

ios - NSURLConnection sendAsynchronousRequest 完成 block 是否在主线程上执行?

我想知道当我使用NSURLConnectionsendAsynchronousRequest时,是否在主线程上调用了completionHandlerblock。我主要关心的是我是否需要自己在主线程上调度UIKit调用。NSURLConnection的文档没有提到这个细节,除非我错过了。我分析了我的代码,没有内存泄漏,这表明该block是在主线程上执行的。有文档给出明确的答案吗?[NSURLConnectionsendAsynchronousRequest:requestqueue:[NSOperationQueuemainQueue]completionHandler:^(NSURL

ios - 使用 dispatch_block 崩溃

我一直在努力了解这次崩溃背后的原因,以便更多地了解block的行为方式。我有一个非常简单的类来触发这次崩溃。@implementationBlockCrashTest-(void)doSomething{dispatch_queue_tqueue=dispatch_queue_create("com.queue.test",DISPATCH_QUEUE_SERIAL);__weaktypeof(self)weakSelf=self;dispatch_block_tblock=^{__strongtypeof(weakSelf)strongSelf=weakSelf;dispatch_g