abh
abh

Reputation: 1249

extract UIButton object from NSString

I want to hide already created UIButton object of same name as contents of string myBtnName

 NSString *str=@"first";
 NSString *myBtnName=[str stringByAppendingString:@"Btn"];

myBtnName is (NSString ) and has value of @"firstBtn"... How do i make it (UIButton) firstBtn ?... Please Help

Upvotes: 0

Views: 249

Answers (3)

Arun
Arun

Reputation: 21

UIButton *button = [button setTitle:[NSString stringWithFormat:@"%@Btn",yourVariableString]   forState:UIControlStateNormal];

Upvotes: 2

philipp
philipp

Reputation: 119

You question is unclear to me, but if you want to get a button that you defined as a property by it's name you can use this:

NSString* myBtn = [str stringByAppendingString:@"Btn"];
UIButton* button = [self valueForKey:myBtn];

Upvotes: 1

Nitin
Nitin

Reputation: 451

don't under stand your question properly but i get your problem little bit. that you want to set title of button by appending your variable try this: this will append your text i.e @"Btn" with your variable: hope this helps.. :)

    UIButton *btn = [btn setTitle:[NSString stringWithFormat:@"%@Btn",yourVariableString]   forState:UIControlStateNormal];

Upvotes: 2

Related Questions