0

I'm new at objective c, I was playing with labels buttons and textboxes, I've a label, text box and two buttons(Add, Clear),

what I want to do is, write something in the textbox and when press to "add" button I want the text to appear on the label , and the clear button should clear label and the text box

I've ran the program and the build is succeed however when i write some text and press return button nothing happens, the virtual keyboard still stays there and text doesn't appear on the label, my codes are as follows:

in the .h file

@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; 

in the .m file

@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

I would really appreciate if someone helps, thanks in advance

P.s : what is the code to end the program if incase I add an exit button?

Thanks again,

Asim Gunduz

Omarj
  • 1,151
  • 2
  • 16
  • 43
AsIm Gunduz
  • 25
  • 2
  • 7
  • When you say "press return button", do you mean the return button on the keyboard or when you click the add button? – Bo A Dec 09 '12 at 19:13
  • Answer to P.S: You cant programmatically end the program. User has to press on home button and dismiss it. You can prompt the user to do this via an alert message. If you disable multitasking, on press of home button will quit the app. – iDev Dec 09 '12 at 20:24

2 Answers2

0

Have you linked everything correctly in your .xib/storyboard?

Read this on how to properly handle the return key.

You should not exit an app with a button. The only way to close your app should be pressing the home button. However, you could use

exit(0);
Community
  • 1
  • 1
FD_
  • 12,947
  • 4
  • 35
  • 62
  • I think I've linked correctly the problem is that I've watched some tutorials on youtube for the helloworld program and when people were doing the linkink it would automatically @synthesize (property) but my xcode doesn't do that, I have to do that manually – AsIm Gunduz Dec 09 '12 at 19:20
  • 2
    if u use exit(0) your app will be reject :( – Omarj Dec 09 '12 at 19:27
  • Yeah, there is no App-Store-Safe way of programmatically closing the app simply because this is against Apple's guidelines. That's why I wrote that you should not do it. – FD_ Dec 09 '12 at 20:09
0

the code looks fine, but you can try these tutorials,

Linking the IBOutlet and IBAction

Hiding Keyboard

MTahir
  • 1,173
  • 1
  • 13
  • 25