设置子视图委托

时间:2015-11-10 14:15:21

标签: ios swift delegates

出于好奇,如何使用for循环设置所有子视图的委托?

for case let i  in (myTest.popoverPresentationController?.presentedViewController.view.subviews)! 
{
   //how do i set the delegate of i?
   i.delegate = self
}

1 个答案:

答案 0 :(得分:-1)

你可以试试这个:

if let subviews = myTest.popoverPresentationController?.presentedViewController.view.subviews {
    for view in subviews {
        if let customView = view as? CustomView {
            customView.delegate = self
        }
    }
}