草庐IT

ios - 带有 completionHandler 的 block 的 Swift 语法...在委托(delegate)方法中

这是常规NSURLSession完成block问题的一个问题,我花了很多时间将其解析为Swift语法。该方法是身份验证委托(delegate)回调,在身份验证挑战时调用;开发人员使用NSURLCredential、NSError调用完成block。Objective-C方法如下所示:-(void)provideUsernamePasswordForAuthChallenge:(NSURLAuthenticationChallenge*)authChallengecompletionHandler:(void(^)(NSURLCredential*,NSError*))completio

ios - 如何在 Swift 中基本实现委托(delegate)?

我正试图让我的头脑围绕委托(delegate)并将其分解为基本实现。我想出了这个,但是委托(delegate)函数永远不会被调用。任何人都可以解释一下吗?protocolMyDelegate{funcdelegatedFunction(a:String)}classDelegatorClass{vardelegate:MyDelegate?funccallDelegate(){delegate?.delegatedFunction("hello")}}classDelegateClass:MyDelegate{funcdelegatedFunction(a:String){print(

ios - 面向协议(protocol)编程和委托(delegate)模式

AWWDC2015sessionvideo描述了面向协议(protocol)编程的思想,我想在我future的应用程序中采用这种技术。为了理解这种新方法,我最近几天一直在研究Swift2.0,并且一直在努力让它与DelegatePattern一起工作。.我有两个协议(protocol)定义了我项目中有趣部分的基本结构(示例代码是废话但描述了问题):1)一个委托(delegate)协议(protocol),使一些信息可访问,类似于UITableViewController的dataSource协议(protocol):protocolValueProvider{varvalue:Int{

swift - 如何同时委托(delegate)ARSession和AVCaptureSession?

我见过有人用ARSCNView运行ARKit,他们能够在相机中获取所说的QR码矩形,并在与QR码所在位置相关的位置渲染一些东西空间。我认为他们是通过委托(delegate)AVCaptureMetadataOutputObjectsDelegate来实现的,所以我继续尝试实现以下逻辑:同时运行ARSCNViewDelegate、ARSessionDelegate和AVCaptureMetadataOutputObjectsDelegate。连接一个ARSCNView,将View及其session委托(delegate)给自己。连接一个AVCaptureSession,将其委托(dele

ios - 不同类中的委托(delegate)和数据源可能吗? - UITableView

当使用UITableView时,有两种类型的方法,即,数据源和委托(delegate)仍然应该连接到相同的父ViewController类。有什么方法可以在不同的类中定义委托(delegate)和数据源吗?为什么我们需要将委托(delegate)和数据源分开?注意:这个问题适用于UICollectionView和类似的对象 最佳答案 正如其他响应中关于委托(delegate)模式的充分解释,我们可以将tableview数据源和委托(delegate)声明为不同的对象,以避免MassiveViewControllers并实现精益Vie

ios - 不调用委托(delegate)方法 (transitioningDelegate)

我正在尝试在两个viewController之间实现自定义转换。(swift3.0)在我的两个viewController之间,我有一个UISegue,类型为show(animated=true)。所以我在我的第一个ViewController的扩展中设置了UIViewControllerTransitioningDelegate的委托(delegate)方法:extensionDocumentsViewController:UIViewControllerTransitioningDelegate{...}而且我还实现了协议(protocol)要求的方法:animationContr

ios - 从未调用过的交互式委托(delegate)方法

我想在ViewController(1)和NavigationViewController(2)之间进行交互式转换。NavigationController由按钮调用,因此在呈现时没有交互式过渡。它可以通过按钮或UIPanGestureRecognizer关闭,因此可以交互地关闭或不关闭。我有一个名为TransitionManager的对象,用于转换,是UIPercentDrivenInteractiveTransition的子类。下面代码的问题在于两个委托(delegate)方法interactionControllerFor...从未被调用。此外,当我按下按钮或滑动(UIPanGe

ios - Swift 语言多播委托(delegate)

我正在尝试在Swift中实现多播委托(delegate)功能。在ObjectiveC中,我们有这个优秀的实现https://github.com/robbiehanson/XMPPFramework/blob/master/Utilities/GCDMulticastDelegate.m我刚刚创建了这个基本功能:protocolMyProtocol:class{functestString()->String;}classMulticastDelegateNode{weakvardelegate:T?init(object:T){self.delegate=object;}}class

ios - 在 Swift 委托(delegate)中保留循环

这个问题在这里已经有了答案:HowcanImakeaweakprotocolreferencein'pure'Swift(without@objc)(7个答案)关闭7年前。我有一个UIViewController,其中有一个UIToolbar。它们从Storyboard中实例化。我为我的UIToolbar创建了一个自定义类。基于一些逻辑,我在上面显示或不显示按钮。UIViewController需要在一些按钮被点击时采取行动。为此,我在UIToolbar中创建了一个委托(delegate)协议(protocol)。目前,当我关闭View时,它会保存在内存中。进一步调查显示我的委托(de

ios - Swift:XCTest 委托(delegate)/协议(protocol)回调(单元测试)

我需要为委托(delegate)/协议(protocol)回调创建一些单元测试。这是我正在尝试测试的实现示例:protocolSomethingWithNumbersDelegate:class{funcsomethingWithDelegate(results:Int)}classSomethingWithNumbers{vardelegate:SomethingWithNumbersDelegate?=nilfuncdoAsyncStuffWithNumbers(number:Int){varnumbers=Int()/*doingsomewiththeinput*/self.de