是否为自定义uitextfield保留周期(强参考)修复程序? [英] Retain Cycle (Strong reference) fix for custom uitextfield?

查看:62
本文介绍了是否为自定义uitextfield保留周期(强参考)修复程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义文本字段类 loginTextFields。我最近注意到,使用这些文本字段的视图控制器没有被释放,我怀疑它与这些文本字段有关系...任何指导都将不胜感激:)我查找了很多

I have a custom text field class, "loginTextFields". I recently noticed that The view controllers in which I use these text fields are not being deallocated, and I suspect that it has something to do with these text fields... Any guidance is greatly appreciated :) I've looked up quite a few stackoverflow posts but none really helped me out.

txt字段类:

class LoginTextFields: UITextField, UITextFieldDelegate {

 override init(frame: CGRect) {
    super.init(frame: frame)

    delegate = self
    setConstraints()
  }
}

视图控制器:

class LoginController: UIViewController {
  @IBOutlet weak var usernameTextField: LoginTextFields!
  @IBOutlet weak var passwordTextField: LoginTextFields!

}

我猜并在其中添加了删除方法当用户从视图控制器中退出时,尝试将loginTextfield类设置为nil(怀疑代理可能与它没有取消分配有关)。我希望这会删除任何有力的参考,但是没有用

I've guessed and added a 'delete' method to the loginTextfield class in an attempt to set everything to nil (was suspecting maybe the delegate had something to do with it not deallocating) when the user segues out of the view controller. I was hoping this would remove any strong reference but it didn't work

  func delete() {
    self.delegate = nil
    self.text = nil
    self.leftSideIcon.removeFromSuperview() //small icon inside text field
    self.removeFromSuperview()
}


推荐答案

UITextField ,以防止其被释放。 在Apple开发人员论坛上查看此线程进行分析。

There is a known retain cycle in UITextField in iOS 11 that prevents it from being deallocated. See this thread on Apple's developer forums for an analysis.

该错误应在iOS 11.2.5中修复,根据此推文

The bug should be fixed in iOS 11.2.5, according to this tweet.

如果您的文本字段对视图控制器有很强的引用,则可能会导致问题。您可以在现在可用的iOS 11.2.5 beta 3上进行测试,看看它是否可以解决您的问题吗?

If your text field has a strong reference back to the view controller, that could cause your problem. Can you test on the iOS 11.2.5 beta 3 available now and see if it fixes your problem?

这篇关于是否为自定义uitextfield保留周期(强参考)修复程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆