开发者

making a text field required in objective-c

I'm currently in the process of developing an app for the iPhone. There is a screen which requires users to enter their data in text format but it can easily be skipped by simply click开发者_如何学Going the 'submit' button. Is there a way I can make these text fields required?


Have you tried de-activating the button unless the text field has something in it?


u can tell the button process to keep an eye on the text field so that if the text field is empty, the button wont process the function it would be like this

-(IBAction) buttonPressed:(id) sender
{
   //----this will process the button function if the textfield is not empty
   if(textField.text != @"")
   {
    >>> do the process <<<
   }
   else
   //----this will show an alert message when the user tries to click button without filling the textfield
   {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error"
                                                message:@"please fill the information first"
                                                delegate:self
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
      [alert show];
      [alert release];
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜