UITextView setBorderStyle 在 iOS 5 模拟器中崩溃
我在一个视图控制器中遇到了一种奇怪的情况,该行在 iOS 5 模拟器中崩溃:
// myTextField is created in a NIB
myTextField.borderStyle = UITextBorderStyleNone;
在设备中(以及 iOS 4.3 上的设备和模拟器)都可以。我已经检查了 NIB 中的连接(甚至删除并重新连接)。此时,代码中 myTextField 的保留计数为 2。我在此之前设置了其他属性(例如,“text”和“userInteractionEnabled”,这些属性不会导致崩溃。
但是,如果我使用此序列,它不会崩溃:
myTextField.borderStyle = 4; // not a defined border style
myTextField.borderStyle = UITextBorderStyleNone;
如果我使用 1、2 或3(定义的样式)而不是“4”(未定义的边框样式),它崩溃了。
在我的其他视图控制器中,我有类似的 textView,并且将 borderStyle 设置为 UITextBorderStyleNone 没有问题
:这是回溯:
Thread 1, Queue : (null)
#0 0x01e0609b in objc_msgSend ()
#1 0x005c1c22 in -[UIView(Hierarchy) _setBackgroundColor:] ()
#2 0x005c3a06 in -[UIView(Rendering) setBackgroundColor:] ()
#3 0x0063eab7 in -[UITextField setBackgroundColor:] ()
#4 0x0063e1b6 in -[UITextField setBorderStyle:] ()
#5 0x000c23e6 in -[DutyEditViewController viewWillAppear:] at /Users/jeff/Applications/iPhone/MyApp/Classes/DutyEditViewController.m:197
#6 0x00651fbf in -[UIViewController _setViewAppearState:isAnimating:] ()
#7 0x0065221b in -[UIViewController __viewWillAppear:] ()
#8 0x006524c3 in -[UIViewController beginAppearanceTransition:animated:] ()
#9 0x00662b71 in -[UINavigationController _startTransition:fromViewController:toViewController:] ()
#10 0x006633df in -[UINavigationController _startDeferredTransitionIfNeeded] ()
#11 0x00663986 in -[UINavigationController pushViewController:transition:forceImmediate:] ()
#12 0x0c894dbd in -[UINavigationControllerAccessibility(SafeCategory) pushViewController:transition:forceImmediate:] ()
#13 0x006635a4 in -[UINavigationController pushViewController:animated:] ()
#14 0x000bf99a in -[DutiesTableViewController tableView:didSelectRowAtIndexPath:] ()
#15 0x0061a71d in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] ()
#16 0x0061a952 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:] ()
#17 0x0025386d in __NSFireDelayedPerform ()
#18 0x020dc966 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#19 0x020dc407 in __CFRunLoopDoTimer ()
#20 0x0203f7c0 in __CFRunLoopRun ()
#21 0x0203edb4 in CFRunLoopRunSpecific ()
#22 0x0203eccb in CFRunLoopRunInMode ()
#23 0x0258a879 in GSEventRunModal ()
#24 0x0258a93e in GSEventRun ()
#25 0x0058aa9b in UIApplicationMain ()
#26 0x0006117d in main ()
#27 0x00002c65 in start ()
我注意到 setBorderStyle: 正在执行 setBackgroundColor:,因此将我的代码更改为:
myTextField.backgroundColor = [UIColor clearColor];
myTextField.borderStyle = UITextBorderStyleNone;
并且不再发生崩溃,但是,背景颜色在 NIB 中被设置为“Clear Color”
。崩溃已经消失,但为什么我必须设置背景颜色(即使 NIB 已经这样做了)的谜团仍然存在。
I have a strange situation in one view controller where this line crashes in the iOS 5 simulator:
// myTextField is created in a NIB
myTextField.borderStyle = UITextBorderStyleNone;
It's okay in the device (and both device and simulator on iOS 4.3). I've checked the connections in the NIB (even deleted and reconnected). myTextField has a retainCount of 2 at this point in the code. I'm setting other attributes (e.g., "text" and "userInteractionEnabled" prior to this point, and those do not cause a crash.
However, if I use this sequence, it does not crash:
myTextField.borderStyle = 4; // not a defined border style
myTextField.borderStyle = UITextBorderStyleNone;
If I use 1, 2, or 3 (defined styles) instead of "4" (an undefined border style), it crashes. "7" works.
In my other view controllers, I have similar textViews, and no problem setting the borderStyle to UITextBorderStyleNone.
Edit: Here's the backtrace:
Thread 1, Queue : (null)
#0 0x01e0609b in objc_msgSend ()
#1 0x005c1c22 in -[UIView(Hierarchy) _setBackgroundColor:] ()
#2 0x005c3a06 in -[UIView(Rendering) setBackgroundColor:] ()
#3 0x0063eab7 in -[UITextField setBackgroundColor:] ()
#4 0x0063e1b6 in -[UITextField setBorderStyle:] ()
#5 0x000c23e6 in -[DutyEditViewController viewWillAppear:] at /Users/jeff/Applications/iPhone/MyApp/Classes/DutyEditViewController.m:197
#6 0x00651fbf in -[UIViewController _setViewAppearState:isAnimating:] ()
#7 0x0065221b in -[UIViewController __viewWillAppear:] ()
#8 0x006524c3 in -[UIViewController beginAppearanceTransition:animated:] ()
#9 0x00662b71 in -[UINavigationController _startTransition:fromViewController:toViewController:] ()
#10 0x006633df in -[UINavigationController _startDeferredTransitionIfNeeded] ()
#11 0x00663986 in -[UINavigationController pushViewController:transition:forceImmediate:] ()
#12 0x0c894dbd in -[UINavigationControllerAccessibility(SafeCategory) pushViewController:transition:forceImmediate:] ()
#13 0x006635a4 in -[UINavigationController pushViewController:animated:] ()
#14 0x000bf99a in -[DutiesTableViewController tableView:didSelectRowAtIndexPath:] ()
#15 0x0061a71d in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] ()
#16 0x0061a952 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:] ()
#17 0x0025386d in __NSFireDelayedPerform ()
#18 0x020dc966 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#19 0x020dc407 in __CFRunLoopDoTimer ()
#20 0x0203f7c0 in __CFRunLoopRun ()
#21 0x0203edb4 in CFRunLoopRunSpecific ()
#22 0x0203eccb in CFRunLoopRunInMode ()
#23 0x0258a879 in GSEventRunModal ()
#24 0x0258a93e in GSEventRun ()
#25 0x0058aa9b in UIApplicationMain ()
#26 0x0006117d in main ()
#27 0x00002c65 in start ()
I notice that the setBorderStyle: is doing a setBackgroundColor:, so changed my code to this:
myTextField.backgroundColor = [UIColor clearColor];
myTextField.borderStyle = UITextBorderStyleNone;
and the crash no longer happens. But, the background color is being set to "Clear Color" in the NIB.
So, the crash is gone, but the mystery of why I must set the background color (even though the NIB is already doing that) remains.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决了。这是 iOS 5.0 的一个错误,在 iOS 5 设备上也存在,而不仅仅是模拟器。如果使用 UIColor 的 colorWithRed:green:blue:alpha: 设置背景颜色,则设置 UITextField borderStyle 属性时会发生崩溃。
如果使用预设颜色(例如,clearColor)设置文本字段的背景颜色,则不会发生崩溃。如果将 borderStyle 设置为其当前值,则不会发生崩溃。
我已向 Apple 提交了一份报告(错误 ID 10381834)。
Solved. It's an iOS 5.0 bug, and it's in iOS 5 on devices, too, not just the simulator. A crash will occur when setting the UITextField borderStyle property if the backgroundColor has been set using UIColor's colorWithRed:green:blue:alpha:.
There is no crash if the text field's backgroundColor has been set using a preset color, e.g., clearColor. There is no crash if borderStyle is set to its current value.
I've submitted a but report to Apple (Bug ID 10381834).
首先,retainCount 是无关紧要的;甚至毫无意义。
其次,如果发生崩溃,那么您会有回溯和/或崩溃报告。发布它。
最后,如果它在模拟器中崩溃但不在设备上崩溃,则可能是模拟器错误。或不。可能是您的应用程序中的一个错误,只会在模拟器中发生灾难性的失败。
没有更多线索就不能说更多。
First, the
retainCount
is irrelevant; meaningless, even.Secondly, if you have a crash, then you have a backtrace and/or crash report. Post it.
Finally, if it crashes in simulator but not on the device it might be a simulator bug. Or not. Could be a bug in your app that only fails catastrophically in the simulator.
Can't say more without more clues.