草庐IT

delegating-constructor

全部标签

ios - Swift 2.2 #selector for delegate/protocol 编译错误

这是我的代码:protocolCustomControlDelegate:AnyObject{funcbuttonTapped(sender:AnyObject)}classCustomControl:UIView{vardelegate:CustomControlDelegate?{didSet{aButton.addTarget(delegate,action:"buttonTapped:"),forControlEvents:UIControlEvents.TouchUpInside)}}从Swift2.2开始,我收到一个要求使用#selector的编译错误。但在这种情况下,我不

swift - 如何在协议(protocol)扩展中设置委托(delegate)

我有多个显示相同类型单元格的ViewController。我想在这样的协议(protocol)扩展中设置委托(delegate):classProductsViewController:UIViewController,ProductShowcase{//otherproperties@IBOutletweakvarproductCollectionView:UICollectionView!vardataSource:DataSource!overridefuncviewDidLoad(){super.viewDidLoad()setupDataSource()setupCollec

ios - 外部类中的 UITableView 委托(delegate)和数据源不起作用

我有一个简单的项目,添加了UITableView作为当前View的subview,以及创建委托(delegate)和数据源的外部tableviewcontroller类。问题是除委托(delegate)didSelectedRowAtIndexPath外,所有工作都正常,当我单击一行时,所有tableview都变成白色,这是代码:主要类:importUIKitclassViewController:UIViewController{overridefuncviewDidLoad(){super.viewDidLoad()//Doanyadditionalsetupafterloadin

swift - 使用 CustomCell(子类)文本字段符合 UITextField 委托(delegate)

我有一个子类CustomCell,它继承self的父类CreateEvent。该子类描述了TableView单元格的各个单元格,它位于CreateEventViewController上。在一个特定的单元格中,我有一个链接到CustomCell文件的文本字段,但是当用户输入文本字段时,我无法从该文本字段获取值。我也无法通过外部触摸关闭键盘并按下返回键,但我主要专注于从文本字段中获取文本。我熟悉在一个普通的swift文件上执行这些功能,但是因为这是一个子类和两个swift文件,所以我不确定该怎么做。这是我的代码:classCustomCell:UITableViewCell,UIText

ios - 单独类中的图像选择器 Controller 委托(delegate)不起作用

我是Xcode和Swift的新手。我目前正在玩StartDevelopingiOSApps(Swift)Apple教程。到目前为止一切正常,除了一件事。本教程在主ViewController类中处理ImagePicker委托(delegate),使其符合UIImagePickerControllerDelegate和UINavigationControllerDelegate协议(protocol)。我想尝试其他方法并将委托(delegate)移动到单独的类。这是我所做的:importUIKitimportFoundationclassMealPhotoDelegate:UIViewC

swift 4 : Simplifying constructor that just sets fields from parameters?

以下Swift4类从传递给构造函数的7个参数中设置7个字段。鉴于此构造函数的唯一工作是将这些参数中的每一个赋值给字段,有没有更简单的代码编写方法?似乎存在大量没有实际好处的重复。publicclassFactoryForListOfKnownApp{privateletreaderForVersion:ReaderForVersionprivateletfinderForNameOfApp:FinderForNameOfAppprivateletlistOfAppName:[AppName]privateletfactoryForVersionFromVersion:FactoryFo

swift - 对 swift 中弱委托(delegate)的困惑

假设我们有一个协议(protocol)protocolMyProtocol{funsomeFunc()}classAClass{vardelegate:MyProtocol?}AClass不关心委托(delegate)是类还是结构。我想要的是有时委托(delegate)可以是一个类,有时可以分配给一个结构。我的问题是我是否应该让委托(delegate)变得“弱”。如果是这样,我必须让MyProtocol成为一个“类协议(protocol)”,这样委托(delegate)就只能是一个类。如果不是,当我将委托(delegate)分配给类时,如何避免保留循环?感谢任何提示!

ios - 自定义单元格中的按钮操作不调用委托(delegate)函数

我在我用作TableView中自定义单元格的View的文件所有者中使用此代码:importUIKitprotocolPostCellViewDelegate:class{funcpostSettingsAction()}classPostCellView:UITableViewCell{weakvardelegate:PostCellViewDelegate?@IBActionfuncpostSettingsClicked(_sender:UIButton){delegate?.postSettingsAction()print("here2")}requiredinit?(coder

swift - 让委托(delegate)在主线程以外的地方运行

我通常想知道如何让swift委托(delegate)在主线程以外的专用线程中运行。更具体地说,我目前正在使用HueSDK4EDK建立我的应用程序与Hue网桥的连接。该过程的一部分是定义状态观察者和连接观察者(作为委托(delegate))来处理传入的事件。privatefuncbuildBridge(withBridgebridge:BridgeInfoModel)->PHSBridge{returnPHSBridge.init(block:{(builder)in...builder?.bridgeConnectionObserver=selfbuilder?.add(self)},

swift - 如何在 App Delegate 中使 Controller 独立?

所以在AppDelegate.swift文件中,我有一个UINavigationController作为RootViewController,一个mainController作为navigationController的topViewController。我在这里实例化了所有数据,因此它可以是独立的。现在,我想将MenuController作为我的topViewController,但我不确定如何从这里调用mainController。更具体地说,我正在创建一个填字游戏,并且一直专注于网格等的逻辑和实现。现在我想在显示填字游戏之前制作一个菜单作为我的第一个屏幕。主菜单->菜单Contr