ios - 使用textview滚动方法时的EXC_BAD_ACCESS AppDelegate

标签 ios swift exc-bad-access

我有一个弹出窗口,当我滚动 TextView 并关闭弹出窗口时,我在应用程序委托(delegate)中获得 EXC_BAD_ACCESS。

下面的代码用于 TextView 滚动

func textViewDidBeginEditing(textView: UITextView) {
    var scrollPoint : CGPoint = CGPointMake(0.0, textView.frame.origin.y + 300)
    isFormInputChanged = true
    self.contentScrollView.setContentOffset(scrollPoint, animated: true)
}

func textViewDidEndEditing(textView: UITextView) {
    self.contentScrollView.setContentOffset(CGPointZero, animated: true)
}

关闭弹窗的代码

    if isFormInputChanged == true
    {
        var pagetitle = dict[constants.lable.WARNING_TITLE]
        var button1Title = dict[constants.lable.YES]
        var button2Title = dict[constants.lable.NO]
        var alertMessage = dict[constants.lable.alert.CANCEL_UNIT_SAVE_ALERT]
        customControllerWithCancelForm(pagetitle!, button1Title: button1Title!, button2Title: button2Title!, alertMessage: alertMessage!)
    }
    else
    {
        var tmpController :UIViewController! = self.presentingViewController
        self.dismissViewControllerAnimated(false, completion: {()->Void in
            self.unitDetailProtocolVar!.closeUnitDetail()
        });
    }

有人可以告诉我我做错了什么吗?

谢谢,

最佳答案

您进行了过多的强制展开。您应该始终执行可选绑定(bind):

  if isFormInputChanged == true 
  {
    if let pagetitle = dict[constants.lable.WARNING_TITLE],
           button1Title = dict[constants.lable.YES],
           button2Title = dict[constants.lable.NO],
           alertMessage = dict[constants.lable.alert.CANCEL_UNIT_SAVE_ALERT] 
    {
        customControllerWithCancelForm(pagetitle, button1Title: button1Title, button2Title: button2Title, alertMessage: alertMessage)
    }
  }
  else 
  {
    self.dismissViewControllerAnimated(false, completion: { () -> Void in
      if let unitDetailProtocolVar = self.unitDetailProtocolVar {
        unitDetailProtocolVar.closeUnitDetail()
      }
    });
  }

关于ios - 使用textview滚动方法时的EXC_BAD_ACCESS AppDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31635919/

相关文章:

swift - 快速按下按钮之间的时间差

swift - 使用 flutter 的 iPhone XS ideviceinstaller 需要 UDID 验证 - 它不再是 40 位数字并且有破折号

c - EXC_BAD_ACCESS(代码=1,地址=0x0)

ios - 根据此崩溃报告,我应该从哪里开始查找?

ios - 如何在不同的 View Controller 中分离模块

ios - 如何禁用 pdf View (PDFKIT) 内部滚动?

ios - UINavigationBar 中的多色后退按钮

swift - Realm 对象的子级 Realm 对象

ios fwrite 函数 EXC_BAD_ACCESS

javascript - iPhone 应用程序 : getting data without a web API