0

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

OMGPOP
  • 1,995
  • 8
  • 52
  • 95

1 Answers1

1

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.

Antonio
  • 71,651
  • 11
  • 148
  • 165
  • I have a lot of buttons (Imagine EmojiView), I don't think it's a good idea to have multiple button actions. Is it possible to tag all the buttons top to bottom and left to right? – OMGPOP Feb 21 '14 at 13:56
  • it's quite tedious, but it works. (I manually assign tags in each action in the ActionButtonsView class so that in view controller I only need to use one – OMGPOP Feb 21 '14 at 14:11