views:

83

answers:

1

I'm trying to debug my iPhone app (a basic counter) and I have a "goto" function to go to a specific number. When testing my app, I noticed that when set the goto without putting anything into the NSTextField, it doesn't return anything. Not a NULL, nil, or anything. NSLogging the input string doesn't even show up in console. No blank message, no NULL message, nothing. If you want to see my code, here it is:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
 switch(buttonIndex) {
     case 0:
        break;
     case 1:
        NSLog(@"Method called");
        NSLog(@"%@", [[alertView textField] text]);
     if ([[alertView textField] text] != NULL) {
        count = [[[alertView textField] text] intValue];
        [label setText:[[alertView textField] text]];
     } else { 
        break;
     }
  }
}

"Method called" always shows up, but the next line doesn't come up at all on a case with no input.

Thanks in advance!

+1  A: 

It doesn't show up because I suspect that it has nothing to show!

If you really want to show it no matter what try:

NSLog(@"Alertview textfield = %@", [[alertView textField] text]);

This way it'll show the first part of the string and then if its got any text to display it'll append that as well

I've just done a very small test and using

NSString* text = @"";
NSLog(@"%@",text);

and nothing is shown in the console

::edit::

If your trying to get the if statement to work you could try using something like

if(![[[alertView textField] text] isEqual:@""])

What it seems is happening is that the [[alertView textField] text] is returning an NSString of @"" and not NULL or nil.

James Raybould
Thanks for the answer, but it still logs as `Alertview textfield = `
esqew
I've updated my answer does that help any?
James Raybould
YES! Thank you... I actually smiled when it worked. Thanks again!!!! I totally forgot about `isEqualToString`... d'oh!
esqew