Francesco S
Francesco S

Reputation: 2315

How to pass a button between two views?

Is it possible to pass a button between two views?

I mean, when the button is clicked it has to call another view and stay while the view behind it pushesToSegue away.

Upvotes: 0

Views: 90

Answers (1)

Raymond Law
Raymond Law

Reputation: 1188

Are you trying to reuse the same button in multiple view controllers? That is not really how things are done normally in iOS.

I suppose you want to pass some data attached to the Button (i.e. its label or tag) to the next view controller. In that case, you would want to pass the data as properties (e.g. NSString, ...etc.). In your next view controller, create the same button in the same position in the storyboard. Then you can set its label from the data you have passed in.

Now if you really want to pass a UIButton to the next view controller, you can still pass it as a property. However, when someone taps the button, the action method that is called is still the one in your first view controller. You could remap it to another action method in the next view controller, but going down this path is against the general rule of thumb.

Upvotes: 2

Related Questions