草庐IT

delegating-constructor

全部标签

swift - swift 3 "nearly match optional requirement"中的所有 6 个应用程序委托(delegate)函数 - 这是什么?怎么修?

昨晚下载了xcode8.2beta,转换了我的大部分代码,但现在卡在了关于应用程序委托(delegate)的六个功能的黄色警告符号:varwindow:UIWindow?funcapplication(application:UIApplication,didFinishLaunchingWithOptionslaunchOptions:[NSObject:AnyObject]?)->Bool{//Overridepointforcustomizationafterapplicationlaunch.returntrue}funcapplicationWillResignActive(

ios - 获取结果 Controller 委托(delegate)在 swift 1.2/xcode 6.3 更新后未调用

我刚刚将我的项目升级到swift1.2。在连续5或6次“转换为最新的Swift”操作之后:),我能够编译它。然后我的很多UI测试都失败了。这是因为我的“NSFetchedResultsControllerDelegate”不再被调用。在(我可能会说)一次非常幸运的尝试之后,我发现这是因为我的委托(delegate)不是NSObject。所以我能够通过子类化NSObject或添加@obj来修复它。之前:classBasicFetchedResultControllerDelegate:NSFetchedResultsControllerDelegate之后:classBasicFetch

ios - 在两个 ViewController(委托(delegate))之间传递数据 - Swift

这个问题在这里已经有了答案:Passingdatabetweenviewcontrollers(46个答案)关闭7年前。我有两个ViewController。FirstVC-我有label和buttonsegue"modal"SecondVC-我有PickerView和button(回到FirstVC):@IBActionfuncbntback(sender:AnyObject){self.dissmissViewControllerAnimatied(true,completion:nil)}然后我在SecondViewController中创建了委托(delegate):proto

swift - 遗留构造函数违规 : Swift constructors are preferred over legacy convenience functions. (legacy_constructor)

我得到一个SwiftLint此行警告:returnUIEdgeInsetsMake(topInset,leftInset,bottomInset,rightInset)这是警告:LegacyConstructorViolation:Swiftconstructorsarepreferredoverlegacyconveniencefunctions.(legacy_constructor)我也在这一行收到警告:returnCGRectInset(bounds,insetX,insetY)LegacyCGGeometryFunctionsViolation:Structextension

ios - 在 Swift 中为 UIPickerView 委托(delegate)方法

刚开始使用Swift,在调用UIPickerView的委托(delegate)方法时遇到问题到目前为止,我已将UIPickerViewDelegate添加到我的类中,如下所示:classExampleClass:UIViewController,UIPickerViewDelegate我还创建了我的UIPickerView并为其设置了委托(delegate):@IBOutletvaryear:UIPickerViewyear.delegate=self现在我无法将以下内容转换为Swift代码:-(NSInteger)numberOfComponentsInPickerView:(UIP

ios - Swift 语言中的委托(delegate)

我有两个Controller,我需要将第一个Controller的功能调用到第二个Controller:在第二个Controller中,我在类中创建了协议(protocol)和初始化委托(delegate):protocoltestProtocol{functestDelegate()//thisfunctionthefirstcontrollers}classSecondViewController:UIViewController{vardelegate:testProtocol?....}@IBActionfunctestDelegateClicked(sender:AnyObj

ios - 带有 "external"数据源和 Swift 中的委托(delegate)的 UIPickerView

我的View中有两个不同的UIPickerView。当我通过Storyboard将数据源和委托(delegate)设置到它们所在的View时,它们工作得很好,但是当我尝试通过如下所述的代码执行此操作时,它不起作用。两个选择器应该有不同的数据来显示(甚至可能代表不同的行为)。因此,我想以编程方式将它们连接到不同的数据源。我试图创建自己的类来实现UIPickerViewDataSource和UIPickerViewDelegate协议(protocol),并将该类的对象连接到我的PickerView,但它不起作用。在运行时抛出一个异常以NSException类型的未捕获异常终止声明如下:2

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{