我用UIView
创建了XIB。我已经为其分配了课程MyViewControl: UIControl
,因此我可以添加内部动作。它有效,触摸在我的课堂内调用。
现在,我创建了UICollectionView
并添加了这个" xib"作为细胞视图。我现在想要在UICollectionViewDelegate
类中处理。所以我这样做了:
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
for v in cell.contentView.subviews {
if let c: MyViewControl = v as? MyViewControl {
c.isUserInteractionEnabled = true
c.addTarget(self, action: #selector(myClick), for: UIControlEvents.touchUpInside)
}
}
}
func myClick(sender: Any){
print("click....")
}
但是,永远不会调用myClick
选择器。如果我将UIButton
添加到MyViewControl
并为此按钮执行相同操作(addTarget
),则会正确调用回调。
答案 0 :(得分:1)
在发送方之前添加下划线_
,将_ sender: Any
作为(_:)
添加#selector
下的action
。myClick(_ :)
。 func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
for v in cell.contentView.subviews {
if let c: MyViewControl = v as? MyViewControl {
c.isUserInteractionEnabled = true
c.addTarget(self, action: #selector(myClick(_:)), for: UIControlEvents.touchUpInside)
}
}
}
func myClick(_ sender: Any){
print("click....")
}
function FileUploadCheck() {
var formData = new FormData();
formData.append('LogoImageUploader', jQuery('#LogoImageUploader')[0].files[0]);
var http = new XMLHttpRequest();
var url = "FileUploadChecker.php";
http.open("POST", url, true);
//when i uncommentated this line, the upload failed, as i tried to manually set the header to the post, but i let XHR to set the header automatically this works.
//http.setRequestHeader("Content-type", "multipart/form-data");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(formData);
}
希望这有帮助