vendredi 19 septembre 2014

How to remove custom view from superview by pushing button in custom view?


Vote count:

0




I want to display my custom view when the cell of the view controller's table view is tapped in my iOS app. And I also want to dismiss the custom view by tapping a button inside the custom view.


However, while I was able to show the custom view when the cell is tapped by an user, I cannot dismiss the custom view by tapping the button inside the custom view - it's crashed by the error: unrecognized selector sent to instance....


So I wonder what is the correct way to put the button inside the custom view and connect the action to it in order to dismiss it. Here's what I did:




  1. Add @IBAction connection to the custom view's .swift file and call self.removeFromSuperview() - this makes the app crash with the error message above.




  2. Add @IBAction connection to my view controller that is called to display the custom view - this cannot be done because when I tried to create the connection, the Xcode doesn't react to the control-drag behaviour.




Also, if I understand it correctly, I cannot add the custom view to the storyboard file because the custom view is not put initially; it's instantiated by tapping the cell on runtime.


So how can I dismiss the custom view by tapping the button? Where should I write the code (i.e. custom view's .swift file or the original VC's .swift file)?



asked 25 secs ago

Gardecolo

1,414






How to remove custom view from superview by pushing button in custom view?

Aucun commentaire:

Enregistrer un commentaire