草庐IT

delegating-constructor

全部标签

ios - Swift 初始化委托(delegate)

对于来自Java/C#/C++背景的Swift语言,我最困惑的事情之一是构造函数委托(delegate)。我有readaboutit,但我在现实生活中遇到了麻烦。我正在制作一个自定义“DateView”来显示日期。importUIKit@IBDesignableclassDateView:UIView{privatelet_dateLabel=UILabel()funcinitLabel(){_dateLabel.frame=CGRectMake(0,0,self.bounds.width,self.bounds.height)addSubview(_dateLabel)}overri

ios - json.swift 错误是 Self.init 未在委托(delegate)初始化程序的所有路径上调用

enterimagedescriptionhere错误如照片在json.swift中出来我不知道怎么解决。请帮帮我‍publicconvenienceinit(nsurl:NSURL){varenc:NSStringEncoding=NSUTF8StringEncodingleterr:NSError?do{letstr:String?=tryNSString(contentsOfURL:nsurl,encoding:NSUTF8StringEncoding)asString//print(str)self.init(nsurl:nsurl)}catchleterrorasNSErro

ios - Swift 中的 ObjC 委托(delegate)回调

在ObjC中,我有一个函数声明为-(void)fubar:(void(^)(NSDictionary*))callback;这就是我将在ObjC中使用的方式fubar(^(NSDictionary*dict){console.log(dict);})桥接后如何在Swift中使用相同的内容? 最佳答案 因为它是最后一个参数,所以它可以用作尾随闭包:fubar{(dict)inprint(dict)//printsdictionary}甚至更短fubar(){print($0)//printsdictionary}Readthesect

swift - 发现所有指向 Controller 的委托(delegate)?

假设你有课classExample:UIViewController,UIScrollViewDelegate{在程序生命周期的任何时候,可能有(比方说)四个小ScrollView,它们将自己嵌入到Example实例中,所以这些ScrollView表示aScrollView.delegate=someExamplebScrollView.delegate=someExample等等。这些信息确实以某种方式存储在someExample中吗?显然,信息存储在aScrollView中——但它是否也存储在someExample中?委托(delegate)连接是双向的还是严格意义上的单向连接?s

ios - 在应用程序委托(delegate)中全局更改色调后临时更改色调

我的iOS应用的颜色主题用于设置应用的全局色调。但是,在某些情况下,这会导致白色背景上出现白色文本(我想避免这种情况)。有什么方法可以临时更改我的全局tintcolor(或为该实例设置特定的tintcolor)?我特别想在应用程序中更改的两个tintcolors是:UINavigationBar.appearance().tintColorUIBarButtonItem.appearance(whenContainedInInstancesOf:[UINavigationBar.self]).tintColor具体来说,我想在无法直接访问View的情况下更改色调颜色(例如,当我使用UI

swift - 将值传递给前一个 viewController,委托(delegate)方法未被调用

我正在从一个函数中获取schoolAddress的值。View消失后,我传递了schoolAddress的值。我试图将学校地址的值从GeoDetailsVC传递给EditChildPoofileVC..提前谢谢protocolDataEnteredDelegate:class{funcsetLocations(info:String)}classGeoDetailsVC:UIViewController{weakvardelegate:DataEnteredDelegate?=nilvarschoolAddress:String=""overridefuncviewDidDisappe

ios - Swift - 调用自定义委托(delegate)方法

我正在使用BMPlayer库并希望实现自定义控件,为此我有以下类确认以下协议(protocol)@objcpublicprotocolBMPlayerControlViewDelegate:class{funccontrolView(controlView:BMPlayerControlView,didChooseDefitionindex:Int)funccontrolView(controlView:BMPlayerControlView,didPressButtonbutton:UIButton)funccontrolView(controlView:BMPlayerContro

ios - 在 Swift 中使用委托(delegate)模式重构 CNContactPicker UI 代码

我已经在ViewController中成功实现了iOS10中iOS提供的CNContactPickerViewControllerContactsUI,因此我可以让用户选择多个联系人来邀请参加一个事件。我试图通过实现委托(delegate)模式来减小这个单一ViewController的大小,但我卡在了黑屏上。我查看了一些资源,并认为我正在调用委托(delegate)并相应地定义协议(protocol)。我有一个ViewControllerCreateEventViewController,它实现了我自定义的ContactsToInviteDelegate。该协议(protocol)如

ios - UITableViewCell 委托(delegate) indexPath

今天真好,我是iOS开发的新手。我正在开发项目,其中有tableViewCell和按钮,progressBar。当我点击这个单元格的按钮indexPath通过委托(delegate)传递给viewController然后用另一种方法我是下载一些数据并在progressBar中显示它的进度。因此,当我点击一个单元格然后点击另一个单元格时,第一个单元格的进度停止并在第二个单元格继续,有人可以帮忙吗?提前致谢)这是viewController中的委托(delegate)方法:funcdidTouchButtonAt(_indexPath:IndexPath){songs[indexPath.

ios - 当前台应用程序发生内存不足崩溃时,调用 App Delegate 生命周期的哪一部分?

尝试调试用户遇到的崩溃,但并未显示在我们的崩溃报告工具或日志文件中。有一种理论可能是由于内存压力,但不确定如果iOS在前台终止应用程序,是否会调用applicationWillTerminate。我们在applicationWillTerminate中写入我们的日志文件,但显然在这次崩溃期间没有调用它。 最佳答案 如果应用程序崩溃,则不会可靠地调用任何生命周期方法。相反,您可以创建并注册一个在这种情况下被调用的全局异常处理程序:funcexceptionHandler(exception:NSException){print("**