2011-10-16 33 views
2

我在這條線中的iOS 5模擬器崩潰一個視圖控制器一種奇怪的情況:的UITextView setBorderStyle崩潰在IOS 5模擬器

// myTextField is created in a NIB 
    myTextField.borderStyle = UITextBorderStyleNone; 

它在裝置好(和器件和模擬器上的iOS 4.3 )。我已經檢查了NIB中的連接(甚至刪除並重新連接)。 myTextField在代碼中此時的retainCount爲2。我設置其他屬性(例如,「文本」和「userInteractionEnabled」之前這一點,而那些不導致崩潰

但是,如果我用這個順序,它不會崩潰。

myTextField.borderStyle = 4; // not a defined border style 
    myTextField.borderStyle = UITextBorderStyleNone; 

如果我使用1,2,或3(定義的樣式),而不是 「4」(未定義的邊界樣式),它崩潰。 「7」 的工作原理。

在我的另一視圖控制器,I具有相似textViews ,並沒有問題的borderStyle設置爲UITextBorderStyleNone。

編輯:這是ba cktrace:

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已經這樣做)仍然存在的奧祕。

+0

感謝回溯;請通過bugreporter.apple.com提交一個錯誤,並附上崩潰版本的應用程序的二進制文件W /重現崩潰的說明。 – bbum

回答

4

已解決。這是iOS 5.0的一個bug,它也在iOS 5上,不僅僅是模擬器。如果使用UIColor的colorWithRed設置了backgroundColor,則設置UITextField borderStyle屬性時會發生崩潰:green:blue:alpha :.

如果使用預設顏色(例如clearColor)設置了文本字段的backgroundColor,則不會發生崩潰。如果borderStyle設置爲當前值,則不會崩潰。

我已經提交了一個報告給Apple(錯誤號10381834)。

+0

當通過Interface Builder將UITextField背景色設置爲'white Color'時,我遇到了這個bug。當選擇「白色」時,該屬性將顯示爲「默認顏色」,但仍然會崩潰。設置爲「Table Cell Grouped Background」爲我固定,但我仍然需要白色。 @Jeff,感謝您在這裏發佈您的發現,並報告錯誤。 – Snips

+0

...我發現了一個解決方法,可以獲得所需的結果:將背景顏色更改爲groupTableViewBackgroundColor,設置borderStyle,然後更改回所需的顏色。作品一種享受。 – Snips

0

首先,retainCount是無關緊要的;毫無意義,甚至。其次,如果你有崩潰,那麼你有一個回溯和/或崩潰報告。發表它。

最後,如果它在模擬器中崩潰但不在設備上,它可能是一個模擬器錯誤。或不。可能是您的應用程序中的一個錯誤,只會在模擬器中發生災難性故障。

沒有更多的線索就不能多說了。

+0

我已經添加了回溯,並發現了一種防止崩潰的方法,但它仍然很神祕。 (我提到了retainCount,因爲我不希望有人建議UITextView不被保留。) – Jeff