Rishabh
Rishabh

Reputation: 3852

How to call - (id)initWithFrame:(CGRect)frame function?

I am creating a UIView class . in the implementation there is a function

- (id)initWithFrame:(CGRect)frame

I am adding a button in the class which is used to reload the class.

I would like to call the class initialization function when the button is pressed so that the view is refreshed and it comes back to its intialization state.

Is there a function which can be used to roll back the view to its intialized state?

Upvotes: 0

Views: 707

Answers (1)

Vladimir
Vladimir

Reputation: 170859

You should not call -init methods more then once for the same object.

The solution for your problem however is simple - move all your setting properties code to a separate function, e.g. -setupDefaultProperties and call it in your initWithFrame method and whenever you want to reset the view to its initial state

Upvotes: 2

Related Questions