简体   繁体   中英

How to find text of UILabel which is set in Interface Builder?

I have UILabel *lblTest . and I set text to this label as "test" in Interface Builder .

now I set lblTest text as "new test" through code.

So now again I want to get "test" text which I already set in Interface Builder .

Is there any way to do this smartly?

NOTE : I am not interested to do number of line code.... Expecting single line solution.

Thanks in Advance.

I guess you want something like an "Undo" functionality. There is no special way to do the thing you describe. One thing you can do is:

  1. Store the first string in an NSString variable before you set the label text as "new test"

     NSString *oldString = lblTest.text; 
  2. Change the text from code.

     self.lblTest.text = @"new test"; 
  3. When you want, change it back to the old string.

     self.lblTest.text = oldString; 

You have to understand that that the values in your Interface Builder will be overwritten by the code code you've wrote yourself.

So once your code has changed the label, you can revert the value of the Interface Builder like:

NSString* lblTestString = lblTestString.text;

//now set your value from the code
[lblTest setText:@"new Test"];

//and revert it to what was already in the interface builder
[lblTest setText:lblTestString];

Still it doesn't make any sense really..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM