草庐IT

Delegate

全部标签

ios - UNUserNotificationCenterDelegate 委托(delegate)方法 "nearly matches optional requirement"

我正在实现funcuserNotificationCenter(_center:UNUserNotificationCenter,didReceiveresponse:UNNotificationResponse,withCompletionHandlercompletionHandler:()->Void){但是我从编译器收到“几乎匹配可选要求”的警告。我的声明有什么问题?我直接从文档中复制了它! 最佳答案 这是@escaping属性。它没有显示在文档中。但它显示在页眉中。这就是复制的地方!这是正确的声明:funcuserNoti

ios - 如何为 CALayer 设置委托(delegate)?

我正在尝试设置一个CALayer的委托(delegate),以便我可以使用draw(_:in:)。documentation描述了如何去做。但是一旦我设置了委托(delegate),就会出现运行时错误:Thread1:EXC_BAD_ACCESS(code=EXC_I386_GPFLT)这是生成错误的代码。在Xcode8.2.1中替换SingleViewApplication模板中的ViewController.swift:importUIKitclassViewController:UIViewController{overridefuncviewDidLoad(){super.vi

ios - 在 swift 中使用 tableView 自动填充委托(delegate)方法的最佳方法?

在swift中编写tableView的委托(delegate)和数据源方法的最佳方法是什么。比如我想写numberOfSectionsInTableView,那么我应该写完整的函数吗?还是自动填充会起作用?overridefuncnumberOfSectionsInTableView(tableView:UITableView)->Int{return1}因为在ObjectiveC的情况下,我只需编写-(NSInteger)number然后使用自动填充,我就能获得整个方法。 最佳答案 使用代码片段来实现这一点。第一步第二步步骤3第四

ios - Swift UITableView 委托(delegate)和数据源声明和保留周期

据我所知,要在swift中使用委托(delegate)模式,我必须像这样声明一个属性:weakvardelegate:TheDelegateProtocol!像这样的协议(protocol):@class_protocolprotocolTheDelegateProtocol{}为了避免保留循环并坚持我们在objective-c中习惯做的事情。现在,如果我查看它们在UITableView定义中的内容,我只会看到:vardataSource:UITableViewDataSource!vardelegate:UITableViewDelegate!和:protocolUITableVie

macos - 为什么 ORSSerialPort 接收委托(delegate)在我的 Swift 项目中不起作用

我有一个简单的SerialController类:classSerialController:NSObject,ORSSerialPortDelegate{varport:ORSSerialPortinit(path:String){port=ORSSerialPort(path:path)port.close()}funcopen(){port.baudRate=9600port.delegate=selfport.open()}funcclose(){port.delegate=nilport.close()}funcSendString(data:String){port.sen

ios - 在 Swift 中调用可选委托(delegate)函数的最佳方法是什么

在Swift中调用可选委托(delegate)函数的最佳方式是什么?假设我有以下协议(protocol):@objcprotocolSomeDelegate{optionalfuncsomeOptionalFunction(sender:AnyObject)}我有这样的类(class):classFoo{vardelegate:SomeDelegate!=nilfuncsomeFunction(email:String,password:String){self.delegate.someOptionalFunction?(self)}}到底该不该这样称呼?如果不是,最佳做法是什么?提

ios - Swift - 委托(delegate)不从其他类调用方法

我试图在按下按钮时更改另一个ViewController中的标签文本。以下是我设置委托(delegate)的方式:在importUIKit下的FirstViewController中@objcprotocolMyDelegate{optionalfuncmakeScore()}在classFirstViewController:UIViewController下的FirstViewController中vardelegate:MyDelegate?在按下按钮时在FirstViewController中delegate?.makeScore!()在SecondViewController

iOS Swift 委托(delegate)语法

我是iOS和Swift的新手。我在理解委托(delegate)中使用的协议(protocol)方法中使用的语法时遇到问题。举个例子,在UIPickerView中使用了下面两个方法:funcnumberOfComponentsInPickerView(pickerView:UIPickerView)->Int{return1}funcpickerView(pickerView:UIPickerView,numberOfRowsInComponentcomponent:Int)->Int{returncount}第一种方法很好,但第二种方法的语法让我感到困惑。第二个参数的格式莫名其妙,据我

swift - 状态保存和恢复 BLE- 调用 didFinishLaunchingWithOptions 但不为 CBCentral 调用任何委托(delegate)方法

我正在开发iPhone应用程序并已实现CBCentralManager。还使用后台模式更新了plist,使用标识符初始化了centralmanager。还在didFinishLaunchingWithOptions中添加了这段代码ifvarcentralManagerIdentifiers:NSArray=launchOptions?[UIApplicationLaunchOptionsBluetoothCentralsKey]as?NSArray{//AwakeasBluetoothCentral//Nofurtherlogichere,willbehandledbycentralM

ios - swift 委托(delegate)不工作

我的ViewController中有一个步进器,用于控制UIView中变量的值。当我在UIView中将变量重置为0时,我也希望步进器和标签重置,但它们不会。我尝试使用委托(delegate),但出现错误。提前致谢!ViewController:protocolCircleViewDelegate:class{funcupdateStepper(view:CircleView)}classViewController:UIViewController,CircleViewDelegate{varcolors=CircleView()@IBOutletweakvarcircleView1: