单击显示按钮时应用程序崩溃,没有红色代码

发布于 2024-10-27 13:16:42 字数 1810 浏览 2 评论 0原文

我正在尝试制作一个单词混搭应用程序(只是作为练习),并且我在代码中解决了所有错误。当我在模拟器中运行应用程序时,除了“混搭单词”按钮之外,一切正常。该应用程序在单击时就会崩溃或冻结。我想我的插座和从笔尖到文件所有者的操作连接可能有问题。任何反馈都会有所帮助,谢谢。

头文件

#import <UIKit/UIKit.h>

@interface Word_CombinerViewController : UIViewController {
    UITextField *word1;
    UITextField *word2;
    UITextField *display;
    UIButton *mashButton;

}
@property (nonatomic, retain) IBOutlet UITextField *word1;
@property (nonatomic, retain) IBOutlet UITextField *word2;
@property (nonatomic, retain) IBOutlet UITextField *display;
@property (nonatomic, retain) IBOutlet UIButton *mashButton;
-(IBAction)textFieldDoneEditing:(id)sender;
-(IBAction)backgroundTap:(id)sender;
-(IBAction)buttonPressed:(id)sender;


@end

主文件

#import "Word_CombinerViewController.h"

@implementation Word_CombinerViewController
@synthesize word1;
@synthesize word2;
@synthesize display;
@synthesize mashButton;


-(IBAction)textFieldDoneEditing:(id)sender {
    [sender resignFirstResponder];
} 

-(IBAction)backgroundTap:(id)sender {
    [word1 resignFirstResponder];
    [word2 resignFirstResponder];
}

-(IBAction)buttonPressed:(id)sender {
    NSString *newText = [word1.text stringByAppendingString:word2.text];
    display.text = newText;
}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}

- (void)viewDidUnload {

}

- (void)dealloc {
    [word1 release];
    [word2 release];
    [display release];
    [mashButton release];
    [super dealloc];
}

@end

另外,这里还有从按钮到文件所有者中的操作的连接的屏幕截图http://i551.photobucket.com/albums/ii448/ktmock/Screenshot2011-03-29at83131PM.png

如果您还需要什么让我知道吗?

I'm trying to make a word mashing app (just as practice), and I got all the errors worked out in the code. When I go to run the app in the simulator, everything works but the "mash words" button. The app just crashes or freezes when it's clicked. I think I might have a problem with my outlet and action connections from the nib to the file's owner. Any feedback would help, thanks.

Header File

#import <UIKit/UIKit.h>

@interface Word_CombinerViewController : UIViewController {
    UITextField *word1;
    UITextField *word2;
    UITextField *display;
    UIButton *mashButton;

}
@property (nonatomic, retain) IBOutlet UITextField *word1;
@property (nonatomic, retain) IBOutlet UITextField *word2;
@property (nonatomic, retain) IBOutlet UITextField *display;
@property (nonatomic, retain) IBOutlet UIButton *mashButton;
-(IBAction)textFieldDoneEditing:(id)sender;
-(IBAction)backgroundTap:(id)sender;
-(IBAction)buttonPressed:(id)sender;


@end

Main File

#import "Word_CombinerViewController.h"

@implementation Word_CombinerViewController
@synthesize word1;
@synthesize word2;
@synthesize display;
@synthesize mashButton;


-(IBAction)textFieldDoneEditing:(id)sender {
    [sender resignFirstResponder];
} 

-(IBAction)backgroundTap:(id)sender {
    [word1 resignFirstResponder];
    [word2 resignFirstResponder];
}

-(IBAction)buttonPressed:(id)sender {
    NSString *newText = [word1.text stringByAppendingString:word2.text];
    display.text = newText;
}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}

- (void)viewDidUnload {

}

- (void)dealloc {
    [word1 release];
    [word2 release];
    [display release];
    [mashButton release];
    [super dealloc];
}

@end

Also here is a screenshot of the connection from the button to the action in the files owner http://i551.photobucket.com/albums/ii448/ktmock/Screenshot2011-03-29at83131PM.png

If you need anything else lemme know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铁憨憨 2024-11-03 13:16:42

在您的buttonPressed方法中放置断点可能会有所帮助,以了解它是否达到了那么远以及它将在哪一行中断。

您可能尚未设置参考网点。按住 Control 键并单击“文件所有者”,然后将蓝色箭头拖动到不同的组件,然后在弹出窗口中选择 ViewController 中要链接到的对象。例如,按钮应链接到 mashButton,一个文本字段应链接到 word1,另一个文本字段应链接到 word2,等等。

It might help to put breakpoints in your buttonPressed method to know if it even makes it that far and on which line it'll break.

You might not have set up your referencing outlets. Control-click on File's Owner and drag the blue arrow to your different components and, in the popup window, select the object in your ViewController to link it to. For example, the button should link up to mashButton, one textfield to word1, another to word2, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文