使用textview滚动方法

时间:2015-07-26 10:29:05

标签: ios swift exc-bad-access

我有一个popover,当我滚动我的textview并关闭popover时,我在app delegate中获得了EXC_BAD_ACCESS。

以下代码用于文本视图滚动

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)
}

解雇popover的代码

    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()
        });
    }

有人可以让我知道我在做什么吗?

谢谢,

1 个答案:

答案 0 :(得分:1)

你正在做太多强行打开。你应该总是做可选的绑定:

  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()
      }
    });
  }