由于“程序接收信号:”EXC_BAD_ACCESS“,”无法处理按钮操作。“

时间:2010-12-16 01:07:12

标签: interface-builder uibutton

现在试图解决这个问题两天了。 我的应用程序有一个文本字段和一个按钮。当文本字段为空时,按下按钮可以让我稳定运行,按下按钮后会收到警报。 但是,如果我在文本字段中键入内容,则按下按钮 - 它会崩溃。 我在调试控制台中可以看到的是: “节目收到信号:”EXC_BAD_ACCESS“。” 没有堆栈细节或任何东西。我的相关代码: 头文件:

#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

------ .m文件:

#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

.Xib文件的一些细节: 动作方法通过“touch-up inside”附加到文件的所有者。 文本字段的出口也连接到它(我也打印了文本的内容,它工作正常)。我还将视图的类标识更改为UICpntrol,因此我可以支持在键入txt时触发视图的事件文本字段,以便键盘将退出...

我做错了什么?

2 个答案:

答案 0 :(得分:1)

msg字符串是常量,释放它可能导致异常。

答案 1 :(得分:0)

在调试器下运行(“构建和调试”)。

调试器窗口(cmd-shift-Y)将显示问题发生位置的回溯,并让您检查该点的变量。