3

I have a UITextView in a UIView. When viewLoad, I had a UIPickerView within a UIAlertView with "OK" button. When I select any value from picker and click "OK" I required to make UITextView active.
For that I have written [<myTextView> becomeFirstResponder]; delegate method of UITextView. As soon as this method execute it make textViewShouldBeginEditing delegate method to be invoked. This method executes correctly and I have return TRUE here, but after that the execution goes back to the line [<myTextView> becomeFirstResponder]; and then the application get crashed.
UIAlertView Delegate method is as below:

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

Here in above code application crash at [self.updateTV becomeFirstResponder];
The crash log shows below:

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

Help me get out of this. I am stuck in this since 2 days.
My project is already on AppStore and that is working correctly. But When I run it in iOS 10 device it create this issue.

Thank you in advance

Er. Vihar
  • 1,495
  • 1
  • 15
  • 29
  • 1
    update your question with textfield textViewShouldBeginEditing method code – Himanshu Moradiya Dec 09 '16 at 06:22
  • You used `[ becomeFirstResponder];` twice? – Bista Dec 09 '16 at 06:23
  • @ Mr.Bista No. I have used the method once. And @ Himanshu Moradiya I have taken UITextView in my codeing and related delegate method is "textViewShouldBeginEditing" only. So I think there is no need to update the question. – Er. Vihar Dec 09 '16 at 06:33
  • @Er.Vihar its problem with your viewconroller present request is different . you present UICompatibilityInputViewController controller but its refernce OGAddUpdateViewController contoller and same textfield in UIInputWindowController so check that controller – Himanshu Moradiya Dec 09 '16 at 06:37
  • UIView its a default view or you create one UIview programically and you add it in main view – Himanshu Moradiya Dec 09 '16 at 06:41
  • That is a default View. My project is already on AppStore and that is working correctly. But When I run it in iOS 10 device it create this issue. – Er. Vihar Dec 09 '16 at 06:44
  • @Er. Vihar can u pls post the code where it crashed? – KSR Dec 09 '16 at 07:14
  • @ Sathi Reddy I have updated my question with the code where the application is crash. – Er. Vihar Dec 09 '16 at 07:21
  • ok i am checking.. – KSR Dec 09 '16 at 07:22
  • Once comment it [self.updateTV becomeFirstResponder] and execute. Pls inform whether it is crashing. – KSR Dec 09 '16 at 07:46
  • @ Mr.Bista @ Himanshu Moradiya @ Sathi ReddyThank you every one for all your great reply and time to help me out of this issue. – Er. Vihar Dec 09 '16 at 08:45

1 Answers1

7

Try this it is working while ...

I encountered this problem before.

Problem:

You have to ensure that the view you will assign to inputView or inputAccessoryView doesn't belong to any parent view. When you create these views from a xib inside a ViewController, by default they are set as subviews of a superview.

Solution Tips:

Use the method removeFromSuperview on the view you will assign to inputView or inputAccessoryView

from : https://stackoverflow.com/a/25882277/3901620

while from xib :

[self.DatePickerView removeFromSuperview];
[Textfield setInputView:self.DatePickerView];
[Textfield setInputView:self.DatePickerView];
Community
  • 1
  • 1
KKRocks
  • 8,222
  • 1
  • 18
  • 84