本文介绍了UITextView setBorderStyle在iOS 5模拟器崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的情况,在一个视图控制器中,这行崩溃在iOS 5模拟器:

  // myTextField在NIB中创建
myTextField.borderStyle = UITextBorderStyleNone;

可以在设备(iOS 4.3和设备和模拟器上)。我检查了NIB中的连接(甚至删除和重新连接)。 myTextField在代码中的这一点上有一个2的retainCount。我在此之前设置其他属性(例如,text和userInteractionEnabled,并且不会导致崩溃。



但是,如果我使用序列,它不会崩溃:

  myTextField.borderStyle = 4; //不是定义的边框样式
myTextField。 borderStyle = UITextBorderStyleNone;



如果我使用1,2或3(定义的样式)而不是4 (一个未定义的边框样式),它崩溃。7工作。



在我的其他视图控制器,我有类似的textViews,没有问题设置borderStyle UITextBorderStyleNone



编辑:这是回溯:

  :(null)
#0 0x01e0609b in objc_msgSend()
#1 0x005c1c22 in - [UIView(Hierarchy)_setBackgroundColor:]()
#2 0x005c3a06 - [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:]()
# UINavigationController_startDeferredTransitionIfNeeded]()
#11 0x00663986 in - [UINavigationController pushViewController:transition:forceImmediate:]()
#12 0x0c894dbd in - [UINavigationControllerAccessibility(SafeCategory)pushViewController:transition:forceImmediate: $ b#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在__CFRunLoopDoTimer()
#20 0x0203f7c0在__CFRunLoopRun()
#21 0x0203edb4在CFRunLoopRunSpecific()
#22 0x0203eccb在CFRunLoopRunInMode()
#23 0x0258a879在GSEventRunModal b $ b#24 0x0258a93e in GSEventRun()
#25 0x0058aa9b in UIApplicationMain()
#26 0x0006117d in main()
#27 0x00002c65 in start()

$

b $ b

  myTextField.backgroundColor = [UIColor clearColor]; 
myTextField.borderStyle = UITextBorderStyleNone;

并且崩溃不再发生。但是,背景颜色在NIB中设置为清除颜色。



所以,崩溃已经消失了,但是为什么我必须设置背景颜色(即使NIB已经在做)。

解决方案

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



如果文本字段backgroundColor已使用预设颜色设置,例如clearColor。如果borderStyle设置为其当前值,则没有崩溃。



我已经提交了一个但是报告给苹果(Bug ID 10381834)。


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.

解决方案

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).

这篇关于UITextView setBorderStyle在iOS 5模拟器崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 16:58