gpt4 book ai didi

objective-c - 自定义 UITableViewCell + UITextField 问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:17 26 4
gpt4 key购买 nike

我遇到了一个我似乎无法弄清楚的问题。

我的设置:

  1. 其中包含多个文本字段的自定义 UITableViewCell。类似于 Apple 在为联系人中的某人添加新地址时的设置方式。
  2. 带有自定义单元格的表格显示为模态视图。此 TableView 还有其他通用单元格(即不是 1. 中所述的自定义单元格)。
  3. 呈现的模态视图在顶部有一个工具栏,其中包含一个完成按钮。按下完成后,模态视图将回调发送回其委托(delegate)并关闭。

我遇到的问题:当用户选择一个 UITextField 并开始编辑时,会出现 UIKeyboard(显然对吗?)。如果键盘打开,并且用户在工具栏上选择“完成”(如 3. 中所述),应用程序会崩溃,因为父 View 试图在键盘打开时关闭模态视图(包含键盘的模态视图) .

高水平看起来它应该像这样工作:

用户点击工具栏中的“完成”-> 检查 UIKeyboard 是否打开 -> 如果打开,则关闭,否则关闭模态视图

但这并不容易。

我一直在努力寻找可行的解决方法,但似乎没有任何效果。

如有任何建议,我们将不胜感激。

编辑

这是崩溃日志:

2011-12-22 16:03:09.021 Renshaw[2308:5f43] bool _WebTryThreadLock(bool), 0xad7a9e0: Tried     to obtain the web lock from a thread other than the main thread or the web thread. This may be     a result of calling to UIKit from a secondary thread. Crashing now...
1 _ZL17_WebTryThreadLockb
2 WebThreadLock
3 -[UITextRangeImpl isEmpty]
4 -[UITextRange(UITextSelectionAdditions) _isCaret]
5 -[UITextSelectionView setCaretBlinks:]
6 -[UIKeyboardImpl setCaretBlinks:]
7 -[UIKeyboardImpl setDelegate:force:]
8 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:]
9 -[UIResponder _finishResignFirstResponder]
10 -[UIResponder resignFirstResponder]
11 -[UITextField resignFirstResponder]
12 -[UIView(UITextField) endEditing:]
13 -[UIWindowController _prepareKeyboardForTransition:fromView:]
14 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
15 -[UIViewController _dismissViewControllerWithTransition:from:completion:]
16 -[UIViewController dismissViewControllerWithTransition:completion:]
17 -[UIViewController dismissViewControllerWithTransition:completion:]
18 -[ListingsViewController postSearch:allObjects:constrainedList:]
19 -[FilterViewController searchObjects]
20 -[NSObject performSelector:withObject:]
21 -[MBProgressHUD launchExecution]
22 -[NSThread main]
23 __NSThread__main__
24 _pthread_start
25 thread_start
[Switching to process 10499 thread 0x2903]
[Switching to process 10499 thread 0x2903]

最佳答案

线索在堆栈跟踪中:

Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

您正在从辅助线程调用 UIKit 方法。您必须在非主线程上执行某些操作,例如调用 resignFirstResponder。有关详细信息,请参见此处:

更新:

事实证明,解决方案是使用以下方式:

dispatch_async(dispatch_get_main_queue(), ^{ <code_here> });

包装关闭 View 的调用,以便 UIKit 方法在主线程上运行。

关于objective-c - 自定义 UITableViewCell + UITextField 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8609895/

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