【问题标题】:UITextView make application crash when becomeFirstResponder called调用 becomeFirstResponder 时 UITextView 使应用程序崩溃
【发布时间】:2017-04-24 13:40:05
【问题描述】:

我在UIView 中有一个UITextView。当 viewLoad 时,我在 UIAlertView 中有一个 UIPickerView"OK" 按钮。当我从选择器中选择任何值并单击“确定”时,我需要使 UITextView 处于活动状态
为此,我编写了UITextView[<myTextView> becomeFirstResponder]; 委托方法。一旦执行此方法,它就会调用 textViewShouldBeginEditing 委托方法。该方法执行正确,我这里返回 TRUE,但之后执行返回到[<myTextView> becomeFirstResponder]; 行,然后应用程序崩溃。
UIAlertView 委托方法如下:

- (void)customIOS7dialogButtonTouchUpInside: (CustomIOS7AlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
    NSLog(@"Button at position %d is clicked on alertView %d.", (int)buttonIndex, (int)[alertView tag]);
    [alertView close];
    [self.updateTV becomeFirstResponder];
}

在上面的代码应用程序崩溃[self.updateTV becomeFirstResponder];
崩溃日志显示如下:

2016-12-09 11:47:53.069049 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.069451 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.070530 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.070970 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.071223 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.072122 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.132574 oGoing[250:11235] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2016-12-09 11:47:53.136872 oGoing[250:11235] [MC] Reading from public effective user settings.
2016-12-09 11:47:53.370813 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.372515 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.372781 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.373559 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.373942 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.374133 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.374921 oGoing[250:11235] self.viewControllers lastObject ==<OGAddUpdateViewController: 0x17bebe00>
2016-12-09 11:47:53.477836 oGoing[250:11235] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x6e208f0> should have parent view controller:<OGAddUpdateViewController: 0x17bebe00> but requested parent is:<UIInputWindowController: 0x17b81400>'
*** First throw call stack:
(0x1c38de07 0x1b5f3077 0x1c38dd4d 0x2146dd8b 0x21d43ba3 0x21d448cd 0x213e11bb 0x21d44655 0x21d3d1c9 0x21497b8f 0x213f9153 0x21456e15 0x21457181 0x2157ff83 0x1b04f5 0x287bb5 0x2140895d 0x214088eb 0x213f2a87 0x21408213 0x21407d5f 0x21402947 0x213d37c9 0x21b73c39 0x21b6d8db 0x1c349c8b 0x1c349795 0x1c347a6b 0x1c297073 0x1c296e81 0x1da3fbfd 0x2143eacf 0x21439201 0xed585 0x1ba6250b)
libc++abi.dylib: terminating with uncaught exception of type NSException

帮助我摆脱困境。自 2 天以来,我就陷入了困境。
我的项目已经在 AppStore 上,并且运行正常。但是当我在 iOS 10 设备上运行它时,它会产生这个问题。

提前致谢

【问题讨论】:

  • 使用文本字段 textViewShouldBeginEditing 方法代码更新您的问题
  • 你使用了两次[&lt;myTextView&gt; becomeFirstResponder];
  • @Mr.Bista 没有。这个方法我用过一次。 @Himanshu Moradiya 我在我的编码中使用了 UITextView,相关的委托方法只是“textViewShouldBeginEditing”。所以我认为没有必要更新问题。
  • @Er.Vihar 它与您的 viewconroller 呈现请求的问题是不同的。您提供 UICompatibilityInputViewController 控制器,但它的引用 OGAddUpdateViewController 控制器和 UIInputWindowController 中的相同文本字段,因此请检查该控制器
  • UIView 是默认视图,或者您以编程方式创建一个 UIview 并将其添加到主视图中

标签: ios objective-c uitextview uitextviewdelegate


【解决方案1】:

试试这个,它正在工作,而...

我以前遇到过这个问题。

问题

您必须确保分配给 inputView 或 inputAccessoryView 的视图不属于任何父视图。当您从 ViewController 中的 xib 创建这些视图时,默认情况下它们被设置为超级视图的子视图。

解决方案提示:

在您将分配给 inputView 或 inputAccessoryView 的视图上使用 removeFromSuperview 方法

来自:https://stackoverflow.com/a/25882277/3901620

当来自 xib 时:

[self.DatePickerView removeFromSuperview];
[Textfield setInputView:self.DatePickerView];
[Textfield setInputView:self.DatePickerView];

【讨论】:

    猜你喜欢
    • 2015-04-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多