UITextView textViewShouldBeginEditing crashes when tapped more than once

4

I have a UIViewController. In this controller I programmatically create a UITextView and set its delegate as my controller. I do this because I dont want to start editing the textView when I tap it.

ViewDidLoad method

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

I implemented the textViewShouldBeginEditing method to return NO here to disable the keyboard from showing up.

textViewShouldBeginEditing method

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

The problem that appears

When I tap the textView it works once, but if i tap it again it will crash the application without any log. The weird thing when I hold the textView and release it, it will work like I want it to work. A normal single tap on the other hand doesn't work a second time.

Edit

Single tapping quickly after each other also seems to work, so it seems that it wont work after i wait x seconds.

After some testing I found out it seems to be an iOS 5.X > bug. When running my App in a 4.3 device/simulator it works like it should. The error log on a iOS 5.1 device says the following:

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
iphone
objective-c
ios
xcode
uitextview
asked on Stack Overflow Apr 17, 2012 by Wesley • edited Apr 17, 2012 by Wesley

5 Answers

1

I did find a solution. I don't really like working around Apple bugs but sometimes you have to. It is three steps...

1) replace the default keyboard with an invisible view

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

2) answer YES to allow editing

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

3) In textViewDidChangeSelection resign the first responder to hide the cursor

- (void)textViewDidChangeSelection:(UITextView *)textView{
    [textView resignFirstResponder];
}
answered on Stack Overflow Jun 20, 2012 by RW. • edited May 14, 2015 by MaxEcho
0

If you don't want to start editing of UITextView when you tapped it:

UITextView* textView = ...;
textView.editable = NO;
0
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{

   [txtView resignFirstResponder];

}

and release txtView in dealloc method

answered on Stack Overflow Apr 17, 2012 by Rinju Jain • edited Sep 5, 2012 by Bo Persson
0

After some testing I found out it seems to be an iOS 5.X > bug. When running my App in a 4.3 device/simulator it works like it should.

Look in my main post where i edited the logfile.

answered on Stack Overflow Apr 25, 2012 by Wesley
0

Swift 4.2 The best and easy way to solve this just make undo manager as false

textView.undoManager?.disableUndoRegistration()

This error appears if you have change the view at run time like within the table, and cell will be reloaded on tapping,

answered on Stack Overflow Nov 27, 2018 by Sazid Iqabal

User contributions licensed under CC BY-SA 3.0