EXC_BAD_ACCESS AppDelegate 当使用 textview scroll 方法时
EXC_BAD_ACCESS AppDelegate when use textview scroll method
我有一个弹出窗口,当我滚动我的文本视图并关闭弹出窗口时,我在应用程序委托中得到 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)
}
关闭弹出窗口的代码
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()
});
}
有人可以告诉我我做错了什么吗?
谢谢,
您强制解包的次数过多。您应该始终执行可选绑定:
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()
}
});
}
我有一个弹出窗口,当我滚动我的文本视图并关闭弹出窗口时,我在应用程序委托中得到 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)
}
关闭弹出窗口的代码
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()
});
}
有人可以告诉我我做错了什么吗?
谢谢,
您强制解包的次数过多。您应该始终执行可选绑定:
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()
}
});
}