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

ukdmbfan

macrumors newbie
Original poster
Sep 17, 2008
5
0
I'm having a bit of a problem whereby anything entered in a UITextField that's passed into a method in a new view controller (which the app subsequently moves to) seems to crash the app if the entered text contains a space and I try and write that string to NSLog or to the new view controller somewhere.

For example, I've got a view controller with: (pseudo-code)

Code:
UITextField *myTextField;

[newViewController handleText:myTextField.text];

And a new view controller with:

Code:
UILabel myLabel;
    
- (void)handleText:(NSString *)myText {
     NSLog([NSString stringWithFormat:@"passed text: %@", myText]);
     myLabel.text = myText;
}

If the text I enter into the UITextField doesn't contain a space, everything works perfectly; but if I do enter a space weird things happen - the NSLog entry causes the app to crash, and setting the text of the label displays something weird, like "( )". I've tried using either %s or %S in place of %@, but then I just get really strange results of bizarre character strings.
 
I don't have much to say about the problem with the spaces in the textfield. I've never encountered anything like that. I.E. Spaces work fine in my textfields. But I have a suggestion for your use of NSLog.

Code:
NSLog([NSString stringWithFormat:@"passed text: %@", myText]);
Instead
Code:
NSLog(@"passed text: %@", myText);
should be sufficient. I.E. the stringWithFormat is extraneous.

I've tried using either %s or %S in place of %@, but then I just get really strange results of bizarre character strings.
That's because %s is intended for null-terminated arrays of 8-bit unsigned characters and %S is for null-terminated arrays of 16-bit Unicode characters, neither of which I doubt you want in this case.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.