gpt4 book ai didi

ios - 由于未捕获的异常 'UIViewControllerHierarchyInconsistency' 终止应用程序,

转载 作者:技术小花猫 更新时间:2023-10-29 10:22:41 25 4
gpt4 key购买 nike

我在选择器上方创建了一个带有两个按钮的工具栏,并在 ios7 上工作,当我在 ios8 中运行时崩溃:

Terminating app two to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller: Should Have parent view controller: but requested parent is: '

这是一段在 ios7 中安静运行的代码:

 expiredPromoTextField.inputView = DatePicker;
expiredPromoTextField.delegate = self;
quantityPromoTextField.inputView = quantityPicker;
quantityPromoTextField.delegate = self;


// Create button to close the UIPickerView
UIToolbar * mypickerToolbar = [[UIToolbar alloc] initWithFrame: CGRectMake (0, 0, 320, 56)];
mypickerToolbar.barStyle = UIBarStyleBlackTranslucent;
[mypickerToolbar sizeToFit];
NSMutableArray * barItems = [[NSMutableArray alloc] init];
UIBarButtonItem * CancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCancel target: self action:selector (cancelDoneClicked)];
[barItems addObject: CancelBtn];
UIBarButtonItem * FLEXspace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: self action: nil];
[barItems addObject: FLEXspace];
UIBarButtonItem * doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target: self action:selector (pickerDoneClicked :)];
[barItems addObject: doneBtn];
[mypickerToolbar setItems: barItems animated: YES];
[quantityPicker setShowsSelectionIndicator: YES];

expiredPromoTextField.inputAccessoryView = mypickerToolbar;
quantityPromoTextField.inputAccessoryView = mypickerToolbar;

你知道我意识到 inputAccessoryView 会使应用程序崩溃,我还询问了 Apple 的工程师,他们告诉我这是测试版的问题,但现在 GM 继续给出同样的问题。

我该怎么办?

最佳答案

我在 iOS 8 上有同样的异常,现在修复为以下代码。

重点是,您不应该将输入 View 添加为 View Controller View 的 subview 。(我不知道为什么代码在 iOS 7 中运行良好,但在 iOS 8 中却不再运行良好。)

之前(发生错误)

UITextField* someTF;
View* customView;
UIViewController *mainVC;

[mainVC.view addSubview:customView];
someTF.inputView = customView;

之后(运行良好)

UITextField* someTF;
View* customView;
UIViewController *mainVC;

// [mainVC.view addSubview:customView]; <-- delete this line
someTF.inputView = customView;

关于ios - 由于未捕获的异常 'UIViewControllerHierarchyInconsistency' 终止应用程序,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25761953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com