DNB5brims DNB5brims - 1 year ago 66
Objective-C Question

Can I get the element by Tag from iPhone SDK?

I want to get back a button, I've already assign the tag to there, how can I do so? Thank you.

Answer Source

Use the viewWithTag method. e.g. if your button is in your controller's view and your button's tag is 100 the following line will return the button:

UIButton *button = (UIButton *)[self.view viewWithTag:100];


Get view with particular tag in Swift -

let view = self.view.viewWithTag(100)

If you want to make sure you have the specific type of view, say a UIButton, you should check the type:

if let button = self.view.viewWithTag(100) as? UIButton {
    //Your code
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download