我是目标 c 的新手,我在玩标签按钮和文本框,我有一个标签、文本框和两个按钮(添加、清除),
我想要做的是,在文本框中写一些东西,当按下“添加”按钮时,我希望文本出现在标签上,清除按钮应该清除标签和文本框
我已经运行了程序并且构建成功但是当我写一些文本并按下返回按钮时没有任何反应,虚拟键盘仍然停留在那里并且文本没有出现在标签上,我的代码如下:
在 .h 文件中
@interface ViewController : UIViewController
@property (retain, nonatomic) IBOutlet UILabel *label;
@property (retain, nonatomic) IBOutlet UITextField *txtbox;
@property (retain, nonatomic) IBOutlet UIButton *btnadd;
@property (retain, nonatomic) IBOutlet UIButton *btnclear;
- (IBAction)btnadd:(id)sender;
- (IBAction)btnclear:(id)sender;
- (IBAction)txtbox:(id)sender;
在 .m 文件中
@implementation ViewController
@synthesize label,txtbox,btnadd,btnclear;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[label release];
[txtbox release];
[btnadd release];
[btnclear release];
[super dealloc];
}
- (IBAction)btnadd:(id)sender {
label.text = (txtbox.text);
}
- (IBAction)btnclear:(id)sender {
txtbox.text=@"";
label.text=@"";
}
- (IBAction)txtbox:(id)sender {
}
@end
如果有人提供帮助,我将不胜感激,在此先感谢
Ps:如果我添加退出按钮,结束程序的代码是什么?
再次感谢,
阿西姆·贡杜兹