Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Bentov

macrumors regular
Original poster
Jul 22, 2007
135
6
Hello,

New to Xcode and iOS programming, but not new to programming overall. Having some odd issues with the iPhone simulator, that I suppose could be normal, but I don't think so. I've created a small app that just has a label, two buttons, and a text field. Simple enough,when the box is clicked, the keyboard comes up, I enter some text, hit a button and the label is changed. The other button just changes the color. I also have it set to make the keyboard disappear if I touch anywhere else on the screen. That all works...but only the first time. After I have ran it once, the keyboard stops coming up when I click the keyboard. Sometimes I have to reset the simulator, sometimes I have to shut it down completely.

Is there something that I'm doing wrong? Or is this normal.?

Thanks,

Bentov
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Sounds like a bug in your app.

You might want to check out a sample app from Apple or somewhere else to see if it does this.

Having said that, I'm not sure what you could do in your code that would prevent the keyboard from appearing when you tap a UITextField.
 

TheWatchfulOne

macrumors 6502a
Jun 19, 2009
832
958
I saw a mention about a bug in iOS 8 which causes the keyboard to not always appear when expected. Could this be a manifestation of such a bug?
 

Bentov

macrumors regular
Original poster
Jul 22, 2007
135
6
Thanks for the replies, Command + K works with no problems. I think you are right Watchful, but I did a little more testing and now I'm wondering if maybe my code is the problem.

After resetting the simulator I run my app, if I click in the textbox, the keyboard comes up and I stop the app. If I run it again, and just click the text box, the keyboard comes up as expected. Once I type anything in the text box, then stop the app, then run it again, the keyboard does not display, but Command + K does work. Does that make any sense?

Here are the relevant bits from ViewController.h and .m
Code:
@property (weak, nonatomic) IBOutlet UILabel *helloLabel;
@property (weak, nonatomic) IBOutlet UITextField *customTextField;
@property (weak, nonatomic) IBOutlet UIButton *clickyButton;
@property (weak, nonatomic) IBOutlet UIButton *clickyButtonColor;

The above properties were made by dragging and dropping from the story board into ViewController.h

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
    // set Label and button text
    self.helloLabel.text=@"default text";
    [self.clickyButton setTitle:@"Change Text" forState:UIControlStateNormal];
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)handleButtonClick:(id)sender {
    //set the label to the contents of the text box and change the color to blue
    self.helloLabel.text = self.customTextField.text;
    self.helloLabel.textColor = UIColor.blueColor;
    
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.customTextField resignFirstResponder];
}

- (IBAction)handleButtonClickColor:(id)sender {
    self.helloLabel.textColor = UIColor.redColor;
}


I also checked and there is only one referencing outlet from the text box and that is too ViewController.h

Thanks,

Bentov
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Few comments on the code:

On iOS we tap buttons. We don't click them.

That touchesBegan is potentially a problem. I would remove that and use a tap gesture recognizer.

For most purposes the touches methods should not be used (any more) and gesture recognizers should be used instead. It's recommended that if you implement one of the touches methods you should implement all of them. But better is to implement none of them.
 

Bentov

macrumors regular
Original poster
Jul 22, 2007
135
6
Thanks again, I will remove the code for the touches and see if the problem goes away.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.