草庐IT

swift - swift Playground 中的简单 swift 委托(delegate)

我对Swift和一般编程还很陌生,对Fortran77有点了解,最近对微Controller进行了一些简单的编程。我正在研究基础知识,一切都很好,直到我遇到一些我无法完全掌握的东西-委托(delegate)。所有的在线帖子都没有完全理解这个概念,至少对我来说是这样,所以为了给自己一些我可以引用的东西,我在Playground上设置了一个基本模板,如下所示。如果我运行下面的代码,它会工作并向终端打印“完成的事情”,但是如果我将协议(protocol)设为“类”协议(protocol),即“协议(protocol)SomeDelegate:类{”,并将“vardelegate”设为“wea

ios - 自定义 UIView 初始化程序的便利初始化程序必须使用 self.init 错误进行委托(delegate)

我正在尝试为UIView创建自定义初始化方法,如下所示:convenienceinit(frame:CGRect,tutorProfileImageURL:String?){self.tutorProfileImageURL=tutorProfileImageURLsuper.init(frame:frame)}overrideinit(frame:CGRect){super.init(frame:frame)setup()}requiredinit?(coderaDecoder:NSCoder){super.init(coder:aDecoder)setup()}funcsetup(

ios - willDisplayCell 委托(delegate)方法 Swift

我一直在围绕tableview工作,但遇到了以下问题。据我所知,willDisplayCell委托(delegate)方法应该允许我访问当前的单元格设计。我的问题是-我无法访问的实例自定义单元格,因为它是在cellForRowAtIndexPath方法中单独声明的。如果我再次声明它-我无法访问它的对象(我在那里有一个uibutton)。或者我可能误解了这种方法的使用。这是我的代码functableView(tableView:UITableView,willDisplayCellcell:UITableViewCell,forRowAtIndexPathindexPath:NSInde

ios - UITabBarController 动画的转换委托(delegate)

我已经创建了一个自定义的UIViewControllerAnimationTransition类,并且需要在它切换选项卡时使它成为UITabBarController的动画。不过,tabBarController不使用常规标签栏。我有一个类似它的自定义实现,当按下按钮时,它会调用此代码:tabBarController.selectedIndex=index目前我有tabBarController(子类)作为它自己的transitionDelegate的委托(delegate)。不过,委托(delegate)方法animationControllerForPresentedContro

ios - 从基类扩展委托(delegate)

我有一个objc基类:@protocolBaseClassDelegate;@interfaceBaseClass:NSObject@property(nonatomic,weak)iddelegate;@end@protocolBaseClassDelegate-(void)baseDelegateMethod;@end我正在创建一个swift子类,我想在其中扩展我的委托(delegate)...protocolSubClassDelegate:BaseClassDelegate{funcadditionalSubClassDelegateMethod();}classSubClas

ios - 单击按钮时 UITextField 不会结束编辑(委托(delegate) textFieldDidEndEditing)

我在屏幕上有两个textFields和一个Submit按钮。用户在第一个文本字段中输入详细信息,然后在第二个文本字段中输入详细信息。我的要求是在单击Submit按钮时结束编辑,并打印这些textFields中的用户输入。我在打印第二个textField的值时遇到问题,因为当用户单击提交按钮时,编辑似乎永远不会结束。这是我的代码。感谢您在此问题上的帮助(我添加了文本字段委托(delegate))importUIKitclassViewController:UIViewController,UITextFieldDelegate{varfirstName=""varlastName=""@

IOS - 委托(delegate)与通知

想听听您对以下架构的看法:在我的应用程序中,我有一个处理异步登录的静态类(LoginManager)。一旦登录阶段完成,应用程序应该响应并转换到另一个状态。我有2个实现建议使用委托(delegate):importFoundationprotocolLoginManagerDelegate{funconLogin(result:AnyObject)}classLoginManager{structWrapper{staticvardelegate:LoginManagerDelegate?}classfuncuserDidLogin(result){Wrapper.delegate?.

ios - 从委托(delegate)返回元组(可选类型的值未展开)

我已经定义了一个带有返回元组方法的协议(protocol):protocolSMCalculatorDelegate{funcnumbersToAdd()->(Int,Int)}当我尝试像这样针对我的类中的委托(delegate)方法调用它时:classSMCalculator:NSObject{vardelegate:SMCalculatorDelegate?funcadd(){letmyTuple:(n1:Int,n2:Int)=delegate?.numbersToAdd()}}我在引用该行代码的.numbersToAdd()部分的letmyTuple...开头的行中收到以下错误

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

我有一个UIViewControllerclassWelcomeViewController:UIViewController和一个UIViewclassSignUpView:UIView现在我想在SignUpView的WelcomeViewController委托(delegate)中设置:protocolSegueDelegate{funcrunSegue(identifier:String)}classSignUpView:UIView{...}并将其连接到classWelcomeViewController:UIViewController,SegueDelegate{我如何在

ios - 如何检测 iOS 上互联网连接的变化,委托(delegate)风格?

我需要一个仅在系统检测到没有互联网连接时运行的函数,然后在系统检测到互联网连接时运行另一个函数。我在想这样的事情:funconInternetConnection(){//Enableactions}funconInternetDisconnection(){//Disableactions,alertuser}我还需要一种检测系统何时重新连接的方法,以便让用户知道它正在重新连接,就像在Facebook的Messenger中一样。我该怎么做?我正在为我的网络层使用Moya/Alamofire。 最佳答案 这适用于Alamofirei