How do you connect the “delegate” outlet of a UITe

2019-02-13 04:14发布

How do you connect the "delegate" outlet of a UITextView to a class that implements UITextViewDelegate protocol?

I can't seem to find an example in the docs

The weird thing is the UITextView's "delegate" outlet has that drag 'n drop interface thingy, like you can wire it up to another widget but of course, I don't want to wire it up to a widget, I want to wire it up to an existing class.

3条回答
放我归山
2楼-- · 2019-02-13 04:26

This is a pretty old question, but I had trouble with it as well and figured I'd share an up-to-date Xcode 5 solution.

You should be able to drag the delegate to the yellow circle with the white square inside of it that's down in that black bar below the view controller on your storyboard. This is not at all obvious, so I've provided a screenshot

enter image description here

查看更多
再贱就再见
3楼-- · 2019-02-13 04:29

If you mean "how do I make an object that is created with code the delegate for my text view", just set the delegate property (this is what dragging in Interface Builder will do for you):

textView.delegate = yourDelegateObject;
查看更多
神经病院院长
4楼-- · 2019-02-13 04:46

To wire up a delegate in Interface Builder:

(1) Drag an appropriate controller into the nibs main window and set the class of the controller to the class of your delegate. For example, if you have an NSObject subclass called "MyDelegateClass", drag an Object controller over and set it's class to "MyDelegateClass".

(2) In the connections inspector for the UITextView, control-click on delegate and connect that to the controller created in step (1).

That's it.

查看更多
登录 后发表回答