Skovie
Skovie

Reputation: 197

Help with Uitextfield

Hey .... im working on a Iphone app ..i cant get this working:

i want this alert to show up if the text field is empty when clicking the button linked to "timedAlarm" and if the text filed has a text i want it to go ahead and do the local notification, every thing works fine, until i put in this code before all the code for the notification, i have tried a lot of ways, but it wont work, either the alert shows up, even if there is a text, or els the alert wont show.

- (IBAction) timedAlarm {

    if (eventText.text != nil){

        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Excuse Me !" 
                                                          message:@"Plz enter an alarm text" 
                                                         delegate:nil 
                                                cancelButtonTitle:@"OK" 
                                                otherButtonTitles:nil]; 

        [message show]; 

        [message release]; 

    }else {

Hope u can help me :-D

Rene Skov

Upvotes: 0

Views: 85

Answers (1)

Vladimir
Vladimir

Reputation: 170849

First of all you show alert if text is entered in textfield (i.e. text property is not nil), so you need to reverse condition you have. Additionally you may want to check if current text is an empty string (user might enter some text and delete it afterwards - in that case text will not be nil).

if (event.text == nil || [event.text length] == 0){
   // Show alert
}
else{
  // Text is ok
}

Upvotes: 1

Related Questions