use nib and storyboard together: connect the nib's button target/action to a controller from the storyboard

StackOverflow https://stackoverflow.com/questions/21935765

Question

I am making a chatting application. I have a separated nib view (ActionButtonsView) for the content of scroll view since it's difficult to edit in storyboard, and I may use different nibs for the content of the same scroll view (e.g. ActionButtonsView, Emoji view, etc)

The file owner of the nib view is ActionButtonsView class, however, I need to connect the buttons to ChatViewController (instead of ActionButtonsView) to trigger some actions. The ChatViewController is in storyboard, not nib.

How can I do that?

enter image description here

Was it helpful?

Solution

Regardless of whether it's possible or not, I wouldn't create a dependency between a view and its view controller that way. What I'd use is a delegate: create a delegate to handle your button events, implement it in the view controller, pass it as delegate to the view, and from the view call the delegate methods in your button event handlers accordingly.

Another option is using NSNotificationCenter - but it's more a tool to broadcast events, whereas in your case it would be a point to point notification.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top