Question

I am a newbie to this Xcode stuff.

Details of my error:

1) I started with utility application in Xcode

2) In my MainView.xibI placed a text field. and linked it to code the easy way.(just dragging in to my MainViewController.h file. ..which declared it and even set both property and synthesize for it.)

3) Now when i run the program .. I see my textfield..I press in it..Keyboard come up... and when i try to type in ..just after 1 or 2 letters it runs an error in UIApplicationMain saying EXC_BAD_ACCESS. I searched it for quite some time and somewhere here only on stack overflow I found a solution to change correction in textField to no .. which solves it... This is not my main problem .. but I want to confirm if this method is okay to keep doing in future....sometime in future I will want to have correction enabled.

4) My main problem is that I want to have my textfield keyboard pop in back when user presses return key on the keyboard. I used this method .. and you can see it I tried several ways to do it .. to check for various methods.

-(BOOL) textFieldShouldReturn:(UITextField *)textField {    
    // if([textField becomeFirstResponder]) {
    NSLog(@"IN FINCTION");
    [textField resignFirstResponder];
    return YES;
}

The program was run with both lines commented and not commented but still every time it hits the end of the function it takes me to the the same error in UIApplicationMain: EXC_BAD_ACCESS.

Also, I did enable zombies but i am not sure if i did it correctly so if any of you guys want info on that.

I checked the code on different version of Xcode.. one was normal and other one was GM.

The console shows the log of IN FUNCTION.

Thanks

Was it helpful?

Solution

You would want to return NO from that method because the way you have it now, you are removing focus (and the cursor) from the textField, but then indicating that you DO want to process the return button. But since you have resigned first responder, there is noone to process the return button being pressed.

Try this:

-(BOOL) textFieldShouldReturn:(UITextField *)textField {    
    [textField resignFirstResponder];
    return NO;
}

From UITextFieldDelegate Protocol docs:

textFieldShouldReturn:

Asks the delegate if the text field should process the pressing of the return button.


If the above doesnt work try this:

Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:

(gdb) info malloc-history 0x543216

Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.

See this article (how-to-debug-exc_bad_access-on-iphone) for more detailed instructions.


If the above also doesnt work try this:

You might also want to try turning off "Auto-Correction" in the simulator keyboard settings. There is a bug in one of the versions of the simulator that can cause a crash when you try to enter text in a text field.

Simulator

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top