iname = textField.text;
iname
is an instance variable, right? If so, you need to take co-ownership of this string, so that the string doesn't die when the text field stops owning it (which will happen if anything, including the user, replaces the text field's value for text
with a new value—a new string). Simply assigning the string's pointer to one of your instance variables does not take ownership of the string. See the Memory Management Programming Guide for Cocoa Touch for more information.
If you don't do that, then your program will crash when you try to send a message to the now-dead object whose pointer you have in iname
.
after that at some point im doing this to make sure that the string is not empty
[iname isEqualToString:@""]
…for example.
the problem is that if the textfield contain one word without space it works great if there is space it crashes!
Sometimes there can be an element of randomness to whether the crash manifests.
The way to prove my theory would be to run your app under Instruments's Zombies instrument. That instrument causes objects with no owners to not die (be deallocated), but instead become zombies. When you send a message to a zombie, you'll get a flag in the Instruments timeline, which you can use to examine the object and its history to find out why it died before it should have/why you're still holding onto it after it died.