开发者

how to keep track of 3 input strings using 1 UITextField

开发者 https://www.devze.com 2023-01-23 18:11 出处:网络
How can i keep track of 3 input strings from using 1 UITextField? I am toggling between 3 different input types (departures, airlines, arrivals) using one UITextField for user input.I save each of th

How can i keep track of 3 input strings from using 1 UITextField?

I am toggling between 3 different input types (departures, airlines, arrivals) using one UITextField for user input. I save each of the 3 in its own NSMutableString object like this(depending on what's being entered or whatever):

depart = [input.text copy];
arrive = [input.text copy];
airline = [input.text copy];

i set the value of the UITextField(depending on what user is entering) using

input.text = [arrive copy];
input.text = [depart copy];
input.text = [airline copy];

i am successfully keeping track of each of the 3 inputs using input.text copy yet i am seeing memory leaking issues while running an Instruments test for leaks. i have a feelin开发者_运维技巧g it is a result of my improper cleanup of using copy. how can i retain each input string and not cause memory leaking issues?


Turn your strings into properties that are retained.

@property (retain) NSString *airline;

Set the value of the properties using self.

self.airline = input.text;

Without using self, you're manually setting the value and bypassing the property, so the text is not retained.

Release the objects in your -(void)dealloc method

Then, when you're editing specific information, you can use the properties to populate the textField

input.text = self.airline;

Does this make sense?


Leaks tool should tell you where the leak is.

Here is pretty obvious though. You should release old data prior to assigning new. Thus, all calls like

depart = [input.text copy];

Should be like

[depart release]; depart = [input.text copy];

Also you should release all strings in the dealloc method of the class.

0

精彩评论

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