delegating-constructor
全部标签 我试图在按下按钮时更改另一个ViewController中的标签文本。以下是我设置委托(delegate)的方式:在importUIKit下的FirstViewController中@objcprotocolMyDelegate{optionalfuncmakeScore()}在classFirstViewController:UIViewController下的FirstViewController中vardelegate:MyDelegate?在按下按钮时在FirstViewController中delegate?.makeScore!()在SecondViewController
我是iOS和Swift的新手。我在理解委托(delegate)中使用的协议(protocol)方法中使用的语法时遇到问题。举个例子,在UIPickerView中使用了下面两个方法:funcnumberOfComponentsInPickerView(pickerView:UIPickerView)->Int{return1}funcpickerView(pickerView:UIPickerView,numberOfRowsInComponentcomponent:Int)->Int{returncount}第一种方法很好,但第二种方法的语法让我感到困惑。第二个参数的格式莫名其妙,据我
我正在开发iPhone应用程序并已实现CBCentralManager。还使用后台模式更新了plist,使用标识符初始化了centralmanager。还在didFinishLaunchingWithOptions中添加了这段代码ifvarcentralManagerIdentifiers:NSArray=launchOptions?[UIApplicationLaunchOptionsBluetoothCentralsKey]as?NSArray{//AwakeasBluetoothCentral//Nofurtherlogichere,willbehandledbycentralM
我的ViewController中有一个步进器,用于控制UIView中变量的值。当我在UIView中将变量重置为0时,我也希望步进器和标签重置,但它们不会。我尝试使用委托(delegate),但出现错误。提前致谢!ViewController:protocolCircleViewDelegate:class{funcupdateStepper(view:CircleView)}classViewController:UIViewController,CircleViewDelegate{varcolors=CircleView()@IBOutletweakvarcircleView1:
我开始使用Swift开发一个简单的应用程序,其中包含一个tableView、一个对服务器的请求以及其他一些东西。我意识到UITableViewDelegate协议(protocol)中的每个方法都以相同的方式命名(我猜它可能与其他协议(protocol)相同)并且通过更改传递给这些方法的参数(顺便称为“tableView”)来实现差异.我想知道为什么Apple会做这样的事情,因为当我尝试从这个协议(protocol)实现方法时有点困惑,因为我不能开始输入“didSele...”只是为了自动完成“didSelectRowAtIndexPath”;相反,我必须键入“tableView”以获
在此处使用swift的表列表中,我想在另一个类ViewController中加载一个类表列表,这个概念在objective-c中有效,但归结为swift委托(delegate)方法不调用我的objective-c@swift代码下面请帮我一些人BackGroundView.h:-#import@interfaceBackGroundViewUIViewController{UITableView*tableView;}@property(nonatomic,retain)UITableView*tableView;-(void)tableList:(UIView*)view1;@end
我需要根据特定条件设置不同的对象作为TableView的数据源和委托(delegate)。但是我无法分配tableview的数据源/委托(delegate),因为它会抛出一些错误。CannotassignavalueoftypeNSObject?toavalueoftypeUITableViewDelegate?我检查了this问答,但这没有用。vardataSourceDelegate:NSObject?classRootViewController:UIViewController{...overridefuncviewDidLoad(){dataSourceDelegate=Ta
我有一个包含多张图片的View,每张图片都旨在从设备的照片库中选择。我遵循了theFoodTrackertutorial中的示例,使用点击手势识别器,每个ImageView一个。我已将每个UIImageView的socket连接到我的ViewController中。选择图像时,我希望将设备照片库中的图像设置为所选UIImageView的图像属性。我想这样做的方法是使用封装到一个采用UIImagePickerControllerDelegate协议(protocol)的类中的闭包。但是,永远不会调用此类上的方法。如果我改为让我的ViewController成为委托(delegate),则
我使用的是swift,我展示了一个NSOpenPanel。在委托(delegate)中,我需要查看发件人的提示以区分要采取的操作:例如funcshow(){...panel.delegate=selfpanel.prompt="xy"panel.run....}funcshow2(){...panel.delegate=selfpanel.prompt="abc"panel.run....}//delegatefuncpanel(sender:AnyObject,shouldEnableURLurl:NSURL)->Bool{letpanelPrompt=(senderas!NSOpe
这个问题在这里已经有了答案:UsingasaconcretetypeconformingtoprotocolAnyObjectisnotsupported(6个答案)关闭5年前。在我的一个类(class)中,我使用了一组委托(delegate)(该类(class)是一个单例)。这会导致保留周期。我知道当我只使用一个委托(delegate)时,我可以通过弱化委托(delegate)来避免保留周期。但这不适用于我的委托(delegate)数组。我怎样才能避免这个保留周期。例子:protocolSomeDelegate:class{funcsomeFunction()}我的类(class)c