In Interface builder, If I right click on a tableView, I get option of delegate and dataSource outlets which at times we connect to the file's owner which is in most cases the View Controller which implements these protocol,
How can I get a similar option for my custom view which has a delegate and a datasource property ?
You'll need to meet these conditions:
Custom Class
should be set to your custom view's class name in Interface Builder (via the Identity Inspector). If your delegate or dataSource object is also a custom view, also make sure that that view's Custom Class is set@interface
for your custom class should decorate its delegate and dataSource properties with IBOutlet
. For example, @property (nonatomic, weak) IBOutlet id <SomeProtocol> delegate;
Create your custom delegate,
@objc protocol CustomDelegate: class {
func itemSelected(_ success: Bool)
}
Create your custom class and property of your custom delegate (Make sure you add @IBOutlet during the property declaration),
class CustomView: UIView {
@IBOutlet weak var cDelegate: CustomDelegate!
//...
//...
//...
}
Now, Go to the Storyboard where you want to add this custom view, Take a UIView and change the class then right click on it, you will able to see the property ("cDelegate") you declared. See the picture for better understanding,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With