2012-04-17 83 views
3

我有一個UIViewController。在這個控制器中,我以編程方式創建一個UITextView並將其代理設置爲我的控制器。我這樣做是因爲我不想在點擊它時開始編輯textView。UITextView textViewShouldBegin多次點擊時崩潰

viewDidLoad方法

UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(9, 10, 302, 200)]; 
[textView setDelegate:self]; 
[self.view addSubview:textView]; 
[textView release]; 

我實現了textViewShouldBeginEditing方法從顯示出來返回NO這裏禁用鍵盤。

textViewShouldBeginEditing方法

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView 
{ 
    NSLog(@"Shouldbegin"); 
    return NO; 
} 

出現

當我點擊它的工作原理一旦TextView的,但如果我再次點擊它,它會導致應用程序崩潰,沒有任何日誌中的問題。奇怪的是,當我拿着textView並釋放它時,它會像我想要的那樣工作。另一方面,正常的單擊不能再次工作。

編輯

單快速點擊後,對方也似乎工作,因此它似乎不會工作後,我等待x秒。

經過一些測試後,我發現它似乎是一個iOS 5.X>錯誤。當在4.3設備/模擬器中運行我的應用程序時,它的工作方式應該如此。一的iOS 5.1設備上的錯誤日誌說以下內容:

Date/Time:  2012-04-17 14:00:49.497 +0200 
OS Version:  iPhone OS 5.1 (9B176) 
Report Version: 104 

Exception Type: EXC_BAD_ACCESS (SIGSEGV) 
Exception Codes: KERN_INVALID_ADDRESS at 0x00000014 
Crashed Thread: 0 

Thread 0 name: Dispatch queue: com.apple.main-thread 
Thread 0 Crashed: 
0 TextInput      0x36bf69e8 TI::Favonius::BeamSearch::choose_hit_test_node(WTF::RefPtr<TI::Favonius::SearchNode> const&, WTF::RefPtr<TI::Favonius::KeyAreaNode> const&, WTF::RefPtr<TI::Favonius::SearchNode> const&, WTF::RefPtr<TI::Favonius::SearchNode> const&) + 12 
1 TextInput      0x36bf6d1e TI::Favonius::BeamSearch::update_for_touch(unsigned int, WTF::PassRefPtr<TI::Favonius::KeyAreaNode>) + 602 
2 TextInput      0x36bfb5c2 TI::Favonius::StrokeBuildManager::update_search_for_touch(unsigned int, int) + 66 
3 TextInput      0x36bfb97c TI::Favonius::StrokeBuildManager::key_down_or_drag_hit_test_for_UI(bool, CGPoint, double, int, int, float, bool, ZT::LayoutDictionaryContext&, bool, int) + 216 
4 TextInput      0x36bddf54 TIInputManagerZephyr::simulate_touches_for_input_string() + 344 
5 TextInput      0x36bed8ba -[TIKeyboardInputManagerZephyr candidates] + 214 
6 UIKit       0x31066616 -[UIKeyboardImpl generateAutocorrectionReplacements:] + 82 
7 UIKit       0x31108a96 __71-[UITextInteractionAssistant scheduleReplacementsForRange:withOptions:]_block_invoke_0 + 370 
8 UIKit       0x3110ec62 -[UITextSelectionView calculateAndShowReplacements:] + 6 
9 Foundation      0x3762192c __NSFireDelayedPerform + 408 
10 CoreFoundation     0x361a1a2c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8 
11 CoreFoundation     0x361a1692 __CFRunLoopDoTimer + 358 
12 CoreFoundation     0x361a0268 __CFRunLoopRun + 1200 
13 CoreFoundation     0x3612349e CFRunLoopRunSpecific + 294 
14 CoreFoundation     0x36123366 CFRunLoopRunInMode + 98 
15 GraphicsServices    0x324e3432 GSEventRunModal + 130 
16 UIKit       0x30e70e76 UIApplicationMain + 1074 
+0

remove [textView release];從你的ViewDidLoad方法,然後嘗試它。 – 2012-04-17 10:18:49

+0

不工作:) – Wesley 2012-04-17 10:21:39

+0

在我身邊它的工作很好。但我使用ARC啓用。 – 2012-04-17 10:26:46

回答

0

經過一些測試後,我發現它似乎是一個iOS 5.X>錯誤。當在4.3設備/模擬器中運行我的應用程序時,它的工作方式應該如此。

看看我編輯日誌文件的主要文章。

+0

如果你不使用ARC,那麼你應該爲textView創建一個屬性(retain,nonatomic),以便它在viewDidLoad方法之後不會被釋放。 – calampunay 2013-05-01 16:48:08

0

如果你不想啓動的UITextView的編輯,當你敲擊它:在的dealloc

UITextView* textView = ...; 
textView.editable = NO; 
+0

我也想知道它是否被點擊:) – Wesley 2012-04-17 11:50:54

+0

嘗試UITapGestureRecognizer – 2012-04-17 13:36:48

0
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView 
{ 

    [txtView resignFirstResponder]; 

} 

和釋放txtView方法

1

我找到了解決方案。我不喜歡圍繞蘋果的錯誤工作,但有時候你必須這樣做。這是三個步驟...

1)用一種無形的視圖

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    myTextView.inputView = customKeyboard; 
} 

2替換默認的鍵盤)回答是允許編輯

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{ 
    return YES; 
} 

3)在textViewDidChangeSelection辭職第一響應隱藏光標

- (void)textViewDidChangeSelection:(UITextView *)textView{ 
    [textView resignFirstResponder]; 
} 
+0

似乎像一個OK工作:-)。我不記得我最終做了什麼來修復它。 – Wesley 2012-06-21 09:16:06

+0

我無法更改鍵盤類型,因爲它必須是數字鍵盤,而其餘的步驟對我來說不起作用。 – 2013-09-28 11:22:48