Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift中的自定义委托方法_Ios_Swift - Fatal编程技术网

Ios Swift中的自定义委托方法

Ios Swift中的自定义委托方法,ios,swift,Ios,Swift,我正在开发一个应用程序,在这个应用程序中,我需要一个按钮的委托方法来识别用户按下了哪个按钮。下面是代码,请让我知道我在哪里出错。委托不工作,没有错误,没有崩溃 import UIKit @objc protocol SAlertViewDelegate { optional func clickedButtonTitle(title:String) } class CustomAlertView: UIView { var delegate:SAlertViewDelegate? fun

我正在开发一个应用程序,在这个应用程序中,我需要一个按钮的委托方法来识别用户按下了哪个按钮。下面是代码,请让我知道我在哪里出错。委托不工作,没有错误,没有崩溃

import UIKit
@objc protocol SAlertViewDelegate {

optional func clickedButtonTitle(title:String)
}

class CustomAlertView: UIView {

var delegate:SAlertViewDelegate?
 func button1Action(sender: UIButton?) {

    let titleLabel=sender?.titleLabel?.text
    self.delegate?.clickedButtonTitle!(titleLabel!)
    removeFromMainView()
}

}
视图控制器:-

import UIKit

class CurrentImageVC: UIViewController,SAlertViewDelegate
{
var alert:CustomAlertView=CustomAlertView()
override func viewDidLoad() {
    super.viewDidLoad()

    alert.delegate=self

    }

//MARK: Custom Delegate
func clickedButtonTitle(title:String)
{
    println(title)
}

}

问题是您需要将委托指定给用于添加子视图的对象

let alertSubView: CustomAlertView = CustomAlertView()
alertSubView.frame=CGRectMake(0,0,1024,768)
alertSubView.delegate=self
self.view.addSubview(alertSubView)

您如何展示您的CustomAlertView?让alertSubView=CustomAlertView()alertSubView.frame=CGRectMake(0,01024768)self.view.addSubview(alertSubView)谢谢伙计,您节省了我的时间:-)欢迎@Saurabh如果您有任何其他问题,请告诉我