objective-c - UITextView setBorderStyle 在 iOS 5 模拟器中崩溃

标签 objective-c crash ios-simulator ios5

我在一个 View Controller 中遇到了一种奇怪的情况,该行在 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”(未定义的边框样式),它会崩溃。 “7”有效。

在我的其他 View Controller 中,我有类似的 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 中的背景颜色被设置为“透明颜色”。

所以,崩溃消失了,但为什么我必须设置背景颜色(即使 NIB 已经这样做了)的谜团仍然存在。

最佳答案

已解决。这是 iOS 5.0 的一个错误,在 iOS 5 设备上也存在,而不仅仅是模拟器。如果使用 UIColor 的 colorWithRed:green:blue:alpha: 设置背景颜色,则设置 UITextField borderStyle 属性时会发生崩溃。

如果使用预设颜色(例如,clearColor)设置文本字段的背景颜色,则不会发生崩溃。如果将 borderStyle 设置为其当前值,则不会发生崩溃。

我已向 Apple 提交了一份报告(错误 ID 10381834)。

关于objective-c - UITextView setBorderStyle 在 iOS 5 模拟器中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7783330/

相关文章:

iPhone iOS NSDate 如何检测日期范围是否包括月初?

ios - IPv6 Apple 更新

崩溃后 Android 小部件无响应/不会更新

Xcode 5.1和模拟器使用中错误

crash - 升级到XCode 3.2.3后,iPhone模拟器崩溃

objective-c - iOS 获取属性类

ios - 如何在 iOS 中单击注销按钮时移动到根 ViewController?

objective-c - NSTextField 子类在 setLineBreakMode : method 上崩溃

r - 什么函数可以中断正在运行的R脚本?

ios模拟器窗口缩放/缩放