텍스트 필드 iOS 8에 입력보기를 추가 할 때 오류 발생
iOS 8에서 내 앱에 사용자 지정 입력보기를 추가 할 때 문제가 있습니다. 이것은 iOS 7에서 완벽하게 작동했지만 iOS 8로 전환하면 모든 것이 실패합니다.
다음은 스택 추적입니다.
2014-06-03 21:23:54.237 MyApp[1910:47245] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x1103f9d40>
should have parent view controller:<StopChooser: 0x11083e200> but requested parent is:<UIInputWindowController: 0x110858800>'
*** First throw call stack:
(
0 CoreFoundation 0x00000001042eee35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000103b919a0 objc_exception_throw + 45
2 CoreFoundation 0x00000001042eed6d +[NSException raise:format:] + 205
3 UIKit 0x00000001023d94cd -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 184
4 UIKit 0x0000000102977a2b -[UIInputWindowController changeToInputViewSet:] + 416
5 UIKit 0x0000000102973f56 -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 185
6 UIKit 0x000000010297826a -[UIInputWindowController setInputViewSet:] + 526
7 UIKit 0x0000000102973c97 -[UIInputWindowController performOperations:withAnimationStyle:] + 50
8 UIKit 0x00000001027559bb -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1054
9 UIKit 0x0000000102422afd -[UIResponder becomeFirstResponder] + 468
10 UIKit 0x00000001023235d3 -[UIView(Hierarchy) becomeFirstResponder] + 99
11 UIKit 0x00000001029cdbfb -[UITextField becomeFirstResponder] + 51
12 UIKit 0x0000000102655d61 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 177
lib: terminating with uncaught exception of type NSException
(lldb)
관련 부분은 상위 몇 줄입니다. 누군가 이것을 설명 할 수 있습니까? 내가 부르는 것은 myTextview.inputView = keyboard; 키보드는 스토리 보드에서 생성되고 IBOutlet을 통해 연결된 UIView입니다.
나는 전에이 문제가 발생했습니다.
문제 :
- 당신은보기 당신이에 할당 할 수 있도록해야한다
inputView또는inputAccessoryView어떤 부모 뷰에 속하지 않습니다. ViewController 내부의 xib에서 이러한 뷰를 만들면 기본적으로 수퍼 뷰의 하위 뷰로 설정됩니다.
솔루션 팁 :
removeFromSuperview할당 할보기 에서 방법 을 사용inputView하거나inputAccessoryView
becomeFirstRespondersuperview에서 입력에 사용하는 View를 제거 하기 직전에 :
mTextField.inputView = mInputVeiw;
[mInputVeiw removeFromSuperview];
[mTextField becomeFirstResponder];
도움이 되었기를 바랍니다.
당신은보기 당신이에 할당 할 수 있도록해야한다
inputView또는inputAccessoryView어떤 부모 뷰에 속하지 않는.
이 오류는 스토리 보드에서 생성 된 (따라서 VC에 추가 된) "입력보기"를 이 충돌을 유발 하거나 유발하지 않고 view설정할 수 없기 때문에 특히 짜증 이납니다.inputViewinputAccessoryView
입력보기가 VC에 추가 view되지 않은 경우 인터페이스 빌더 스토리 보드에서 시각적 편집에 입력보기를 사용할 수 없습니다. 스토리 보드의 왼쪽 창에서만 볼 수 있습니다.
Xcode Storyboard의 "Simulated Metrics"도구 모음을 실제 IBOutlet UIToolbar에 연결하는 방법은 무엇입니까?
inputAccessoryView스토리 보드 에서 직접 IB 연결을 만들고 싶습니다 . 이로 인해 충돌이 발생합니다. 내가 찾은 해결책은 Storyboard의 뷰에 연결된 보조 IBOutlet을 만든 다음 viewDidLoad수퍼 뷰 에서 제거한 다음 즉시 inputAccessoryView. 내가 이것을 사용하게 될지 확실하지 않습니다.
- (void)viewDidLoad {
// ...
[self.keybordView removeFromSuperview];
self.inputAccessoryView = self.keybordView;
}
나는 그것을 알아. 이전에 문제가 무엇인지 확실하지 않지만 UIView인터페이스 빌더 를 연결하는 대신 UIView프로그래밍 방식으로 생성 했고 제대로 작동했습니다.
내 문제는 textField 'inputAccessoryView'가있는 뷰의 이름을 지정했다는 것입니다.
@property (weak, nonatomic) IBOutlet CustomView *inputAccessoryView;
오류:
Terminating app due to uncaught exception
'UIViewControllerHierarchyInconsistency', reason: 'child view
controller:<UICompatibilityInputViewController: 0x7fed7063a1a0> should
have parent view controller:<MyViewController: 0x7fed70606f00> but
requested parent is:<UIInputWindowController: 0x7fed710cde00>'
해결책:
이름을 확인하십시오. 필요하지 않은 경우 재정의하지 마십시오.
내 UITextField에서 UIDatePicker를 설정하려고 할 때 동일한 문제가 발생했습니다.
- (void)setupViews {
...
dobField.inputView = aDatePicker; // Here was the problem
...
}
My solution, I just "alloc" and "init" my datePicker in ViewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
...
aDatePicker = [[UIDatePicker alloc] init]; // My solution
...
}
I found the solution creating the UIView programmatically (Like suggested by Milo), but it crashes when its used like a @property. In my case, I needed to create the UIPickerView instance in viewDidLoad and assing to UITextView inputView. When I need to acess the pickerView I get it like this
UIPickerView *picker = (UIPickerView *)self.myTextField.inputView;
Yeah, the Tuyen Nguyen solution did not work for me. What worked for me in iOS 8 / Xcode 6 for setting an inputAccessoryView was not to removeFromSuperview but instead:
[[UIApplication sharedApplication].keyWindow addSubview:**MyViewToBeTheUIAccessoryView**];
I hope this helps someone.
Calling removeFromSuperView in viewDidLoad doesn't seem to work properly in modals. I ended up setting the view hidden, and then removing it from superView in viewDidAppear.
Most answers I was were related to code changes. I found out that deleting an outlet to the UIView inside the main view fixed it. https://stackoverflow.com/a/40037236/464313
My solution for this problem was to add view to inputView, but not to add view controller to parent.
I had the same error when I return any view from storyboard as inputAccessoryView. I fixed it with childViewController. See my answer here.
참고URL : https://stackoverflow.com/questions/24029113/error-when-adding-input-view-to-textfield-ios-8
'Nice programing' 카테고리의 다른 글
| jQuery없이 'data-'속성에 액세스 (0) | 2020.11.23 |
|---|---|
| 해시는 파이썬에서 무엇을합니까? (0) | 2020.11.23 |
| 빈 / 널 값이있는 HashMap에 데이터를 키로 저장하는 것이 좋은 생각입니까? (0) | 2020.11.23 |
| 파일 변경시 Firefox 자동 새로 고침을하려면 어떻게해야합니까? (0) | 2020.11.23 |
| C ++ : 임시 인수의 수명? (0) | 2020.11.23 |