简体   繁体   中英

Xcode: how to set delegates for subviews created using Storyboard?

here is my problem.

I have a viewcontroller in which I create 2 views using UIView(top view and bottom view) and each view has a button. I generate the Top view programatically along with the button, and set the delegate. The top view works -- when the click the button, I see the NSLog "button clicked" in the delegate in viewcontroller.

I've created teh bottom view using Storyboard so that I can see the view and the button placement visually. This doesnt work. I dont see the button click log either in the the button click method associated with the view before it hands over to the delegate defined in the view controller.

How do I set delegates for buttons and other objects created in subviews using Storyboard?

Left click on the (visual) UIButton in the storyboard file. You will see a small menu that pops up. The menu will show a list of properties (including the delegate property) for that object. Then simply right click on the delegate property, hold it, and drag it (a blue line will appear) and link it to the object's delegate.

This link might also help: http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM