簡體   English   中英

調用becomeFirstResponder時,UITextView使應用程序崩潰

[英]UITextView make application crash when becomeFirstResponder called

我在UIView有一個UITextView 當viewLoad時,我在UIAlertView有一個UIPickerView ,帶有“OK”按鈕。 當我從選擇器中選擇任何值並單擊“確定”時,我需要激活UITextView
為此,我寫了[<myTextView> becomeFirstResponder]; 委托UITextView方法。 只要此方法執行它,就可以調用textViewShouldBeginEditing委托方法。 這個方法正確執行,我在這里返回TRUE,但之后執行返回到行[<myTextView> becomeFirstResponder]; 然后應用程序崩潰了。
UIAlertView Delegate方法如下:

- (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設備中運行它時會產生這個問題。

先感謝您

試試這個它正在工作...

我之前遇到過這個問題。

問題

您必須確保您將分配給inputView或inputAccessoryView的視圖不屬於任何父視圖。 當您從ViewController中的xib創建這些視圖時,默認情況下它們被設置為superview的子視圖。

解決方案提示

在要分配給inputView或inputAccessoryView的視圖上使用removeFromSuperview方法

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

來自xib:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM