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

Sergio10

macrumors regular
Original poster
Oct 3, 2007
137
0
hi,
Is it possible to change title using object id of the control?
Is any ways to do this?

Thanks
 
afaik not.
like anything else when you want to connect IB with xcode, you have to make an IBOutlet and you can then access your UI-Element in your code.

btw: you COULD use tags btw, but I think you cannot use the id
 
so how to change title by tag?
Could please write a sample?

tahnks
 
You would have to loop through all the subviews in the button's superview (possibly recursively) and find a control that is a button and has the tag you're looking for. Unless you have some weird setup of your UI that requires this, don't. Use an IBOutlet.
 
could you please write code. i have 7 buttons with tags: 1, 2, 3 ...

how to change title of the button with tag 3 ?

please help me.
thanks
 
could you please write code. i have 7 buttons with tags: 1, 2, 3 ...

how to change title of the button with tag 3 ?

please help me.
thanks

like he said: you loop through the subviews array of the UIView where all those buttons lie on. then you simply check the tag-property of each subview if it is "3" ... if it is, then that is your button and you can do with it whatever you want.

I don't think anyone here will give you the code so you can just copy&paste it, because you should be able to do these things on your on. look at for-loops in objective-c or how to go through arrays in general.
 
The Object ID in IB is only part of IB, it isn't revealed in code.

You set the tag in IB and use it to access the view in code. In your View controller you do something like this

Code:
UIButton* button = (UIButton *)[self.view viewWithTag:myTag];
[button setTitle:myTitle forState:UIControlStateNormal];
 
Thanks for reply!!

What should I put instead of "self.view" in this code?:
PHP:
UIButton* button = (UIButton *)[self.view viewWithTag:myTag];
[button setTitle:myTitle forState:UIControlStateNormal];
As I understood pointer to my view where should to find? Is it correct? Please help with this issue.
 
First, look at the documentation for viewWithTag:, that may clear things up for you.

But, as I said, if this code runs in your view controller then self.view is correct. It just needs to be a view that is at any higher level in the view hierarchy than the view you're looking for, a container view. Normally self.view is the container view for all other views for a view controller.
 
Ohh, I understood.

But I don't use any View. I placed my controls (UIButton, UILabel) in UIWindow. How to solve this problem?
 
UIWindow is a UIView. Use your window.

In most cases one would have a view that gets added to the window and that would be the main container. This would make switching between view easier. But if you didn't do it that way then just use the window.
 
Ohh, I understood.

But I don't use any View. I placed my controls (UIButton, UILabel) in UIWindow. How to solve this problem?

you shouldn't do that anyway, use a UIViewController ... and ysou should learn objective-c basics btw!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.