Can't handle button action due to "Program received signal: “EXC_BAD_ACCESS”."
Tried to deal with this problem for two days now. My app has a text field and a button. when the text field is empty, pressing the button gives me a stable run and i receive an alert after pressing the button. However, if i am typing something in the text field, then pressing the button - it crashes. All i can see in the debug console is: "Program received signal: “EXC_BAD_ACCESS”." There is no stack detail or anything. My relevant code: the header file:
#import <UIKit/UIKit.h>
@interface SpyTextViewController : UIViewController {
int sliderSpeed;
IBOutlet UITextField *textInput;
}
@property (nonatomic, retain) IBOutlet UITextField *textInput;
- (IBAction)sliderChanged:(id)sender;//speed of text show changed
- (IBAction)textFieldDoneEditing:(id)sender;//dor 'DONE' on keyboard
- (IBAction)backgroundTap:(id)sender;//for handling tapping on background
- (IBAction)textEmButtonPressed:(id)sender;
@end
------ the .m file:
#import "SpyTextViewController.h"
#import "txtViewController.h"
@implementation SpyTextViewController
@synthesize textInput;
- (IBAction)sliderChanged:(id)sender
{
UISlider *slider = (UISlider *)sender;
sliderSpeed = (int)(slider.value + 0.5f);//setting the speed determinned by the usr in slider
}
- (IBAction)textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder];
NSLog(@"our text input is %@", textInput.text);
}
- (IBAction)backgroundTap:(id)sender
{
[textInput resignFirstResponder];
}
- (IBAction)textEmButtonPressed:(id)sender
{
NSLog(@"our text input length is %@", [textInput.text length]);
/*
if ([textInput.text length])
{
NSLog(@" inside the tvc init ");
//create the sub MVC
txtViewController *tvc = [[txtViewController alloc] init];
tvc.scrollSpeed = sliderSpeed;
tvc.scrollTxt = textInput.text;
[self.navigationController pushViewController:tvc animated:YES];
[tvc release];
//run text using speed;
}
else */
{
//tell 'em to input text with some pop-up
NSString *msg = nil;
msg = @"Write text to transmit";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Forgot something?"
message:msg
delegate:self
cancelButtonTitle:@"Back"
otherButtonTitles:nil];
[alert show];
[alert release];
[msg release];
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[textInput release];
[super dealloc];
}
@end
Some detail on the .Xib file: the action method is attached to file's owner through "touch-up inside". the text field has its outlet connected to it also (i also printed the contents of the text, it works fine).I also changed the view's class iden开发者_开发知识库tity to be UICpntrol so i could support the event of tapping on the view while typing txt in the text field so that the keyboard will be exited...
What am i doing wrong?
msg string is constant, and releasing it may have caused the exception.
Run under the debugger ("Build and Debug").
The debugger window (cmd-shift-Y) will show the traceback of where the problem occurred, and let you examine variables at that point.
精彩评论