- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我手头有一个非常原始的问题,那就是当我将点击手势识别器添加到我的自定义单元格时,我无法调用 didSelectRowAt
方法。
我的代码如下:
import UIKit
class LanguageViewController: UIViewController {
@IBOutlet weak var titleLabel: AvenirUILabel!
@IBOutlet weak var backButton: UIButton!
@IBOutlet weak var submitButton: PinkUIButton!
@IBOutlet weak var addLanguageButton: UIButton!
@IBOutlet weak var addAnotherLanguageLabel: UILabel!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var tableViewHeightConstraint: NSLayoutConstraint!
var numberOfLanguagesSpoken = 2
var pickersStartHeight: CGFloat!
let downArrowImage = UIImage(named: "arrow_drop_down")
let BGColor = UIColor.white.withAlphaComponent(0.1)
var tag = 1001
var selectedCellHeight: CGFloat = 88.0
var unselectedCellHeight: CGFloat = 44.0
var selectedCellIndexPath: IndexPath?
let languages = ["Akan", "Amharic", "Arabic", "Assamese", "Awadhi", "Azerbaijani", "Balochi", "Belarusian", "Bengali", "Bhojpuri", "Burmese", "Cebuano", "Chewa", "Chhattisgarhi", "Chittagonian", "Czech", "Deccan", "Dhundhari", "Dutch", "Eastern Min", "English", "French", "Fula", "Gan Chinese", "German", "Greek", "Gujarati", "Haitian Creole", "Hakka", "Haryanvi", "Hausa", "Hiligaynon/Ilonggo", "Hindi ", "Hmong", "Hungarian", "Igbo", "Ilocano", "Italian", "Japanese", "Javanese", "Jin", "Kannada", "Kazakh", "Khmer", "Kinyarwanda", "Kirundi", "Konkani", "Korean", "Kurdish", "Madurese", "Magahi", "Maithili", "Malagasy", "Malay", "Malayalam", "Mandarin", "Marathi", "Marwari", "Mossi", "Nepali", "Northern Min", "Odia", "Oromo", "Pashto", "Persian", "Polish", "Portuguese", "Punjabi", "Quechua", "Romanian", "Russian", "Saraiki", "Serbo-Croatian", "Shona", "Sindhi", "Sinhalese", "Somali", "Southern Min", "Spanish", "Sundanese", "Swedish", "Sylheti", "Tagalog/Filipino", "Tamil", "Telugu", "Thai", "Turkish", "Turkmen", "Ukrainian", "Urdu", "Uyghur", "Uzbek", "Vietnamese", "Wu", "Xhosa", "Xiang ", "Yoruba", "Yue ", "Zhuang", "Zulu"]
var proficiency = ["Basic","Conversational","Proficient","Fluent","Native"]
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = backgroundTint
// initial set up
let height = self.view.bounds.height
titleLabel.textColor = .white
backButton.addTarget(self, action: #selector(goBack), for: .allTouchEvents)
tableView.dataSource = self
tableView.delegate = self
tableView.register(LanguageProficiencyTableViewCell.self, forCellReuseIdentifier: "Language")
tableView.backgroundColor = backgroundTint
tableView.allowsSelection = true
tableViewHeightConstraint.constant = 2*height/9
addLanguageButton.tintColor = .white
addLanguageButton.addTarget(self, action: #selector(addNewLanguage), for: .allTouchEvents)
addAnotherLanguageLabel.textColor = .white
submitButton.addTarget(self, action: #selector(submitChanges), for: .allEvents)
}
override func viewWillLayoutSubviews() {
unselectedCellHeight = self.view.bounds.height/9
selectedCellHeight = CGFloat(unselectedCellHeight * 2.0)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func goBack() {
self.dismiss(animated: true, completion: nil)
}
func submitChanges() {
self.dismiss(animated: true) {
//
}
}
func addNewLanguage() {
numberOfLanguagesSpoken += 1
UIView.animate(withDuration: 0.5) {
//
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
extension LanguageViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return numberOfLanguagesSpoken
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Language", for: indexPath) as! LanguageProficiencyTableViewCell
cell.parentVC = self
cell.backgroundColor = .clear
cell.languages = self.languages
cell.proficiency = self.proficiency
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if selectedCellIndexPath == indexPath {
return selectedCellHeight
} else {
return unselectedCellHeight
}
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
//
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if selectedCellIndexPath != nil && selectedCellIndexPath == indexPath as IndexPath {
selectedCellIndexPath = nil
} else {
selectedCellIndexPath = indexPath as IndexPath
}
tableView.beginUpdates()
tableView.endUpdates()
if selectedCellIndexPath != nil {
// This ensures, that the cell is fully visible once expanded
tableView.scrollToRow(at: indexPath as IndexPath, at: .none, animated: true)
}
}
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
return indexPath
}
}
import UIKit
class LanguageProficiencyTableViewCell: UITableViewCell {
let languageLabel = IndentedTextUILabel()
var languagePicker = UIPickerView()
weak var parentVC: LanguageViewController!
var cellHeight: CGFloat = 80
var open = false
var languages = [""]
var proficiency = [""]
var pickedLanguage = ""
var pickedProficiency = ""
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.contentView.addSubview(languageLabel)
self.contentView.addSubview(languagePicker)
self.contentView.backgroundColor = .clear
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
override func layoutSubviews() {
let width = self.bounds.width
let height = cellHeight
let BGColor = UIColor.white.withAlphaComponent(0.1)
languageLabel.frame = CGRect(x: 0.0, y: 1.0, width: width, height: height - 1.0)
languageLabel.textColor = .white
languageLabel.backgroundColor = BGColor
languageLabel.text = "Language(Proficiency)"
languageLabel.leftInset = 25.0
let downArrow = UIButton()
let downArrowImage = UIImage(named: "arrow_drop_down")
downArrow.setImage(downArrowImage, for: .normal)
downArrow.center.y = height/2
downArrow.center.x = 4 * width/5
languageLabel.addSubview(downArrow)
let tap = UITapGestureRecognizer(target: self, action: #selector(cellTapped))
self.addGestureRecognizer(tap)
languagePicker.frame = CGRect(x: 0.0, y: self.cellHeight + 1.0, width: self.bounds.width, height: 0.0)
languagePicker.delegate = self
languagePicker.dataSource = self
languagePicker.backgroundColor = UIColor.white.withAlphaComponent(0.05)
languagePicker.selectRow(20, inComponent: 0, animated: true)
let backGroundView = UIView(frame: CGRect(x: 0.0, y: 1.0, width: width, height: height - 1.0))
backGroundView.backgroundColor = .clear
self.selectedBackgroundView = backGroundView
}
func cellTapped() {
UIView.animate(withDuration: 0.2, animations: {
if !self.open {
self.languagePicker.frame.size.height = self.cellHeight - 2.0
} else {
self.languagePicker.isHidden = true
}
}, completion: { (_) in
if self.open {
self.languagePicker.frame.size.height = 0.0
self.languagePicker.isHidden = false
}
self.open = !self.open
})
}
}
最佳答案
它不起作用,因为点击手势本身进行点击,而不是将点击发送到其下方的 View 。
您可以通过点击手势发送要传递到背景 View 的点击
mySwipeGesture.cancelsTouchesInView = false
如 How to pass a 'tap' to UIButton that is underneath UIView with UISwipeGestureRecognizer? 中所述
此外,如果您只是使用点击手势来关闭键盘,则可以在 tableView 的 didSelectAt 方法中执行此操作,并在该方法中关闭键盘后执行任何其他操作。
关于ios - tableView(_ tableView : UITableView, didSelectRowAt indexPath: IndexPath) 当我将 UITapGestureRecognizer 添加到自定义 UITableViewCell 时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40583461/
有没有办法检测用户所做的旋转是顺时针还是逆时针方向??? 我搜索过但找不到答案! 我的代码如下所示: UIGestureRecognizer *recognizer; recognizer = [
我正在使用 UITapGestureRecognizer 进行双击。当我双击 UIButton 时,它可以工作。但我想避免它吗?有内置方法吗? 最佳答案 您可以通过设置以下 bool 值来阻止 UIT
我有以下代码: - (void)viewDidLoad { UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init
我有一个主视图 Controller ,它被称为WelcomeViewController。我有一个 UIView 子类,其中有一些与 View 相关的内容。我想向该子类添加一个 UITapGestu
UITapGestureRecognizer 不适合我,我想知道是否有人可以提供帮助。 这是我的 View 定义: @interface MainDisplayView : UIView 在实现中,
这太奇怪了,我创建了一个新项目来测试我是否要疯了。 您可以在这里查看项目 https://github.com/ojfoggin/TapTest 我创建了一个带有 UITabBarController
是否可以为触地事件设置 UITapGestureRecogniser?默认是修饰... 最佳答案 不,这是不可能的,但继承 UIGestureRecognizer 应该不难创建您自己的识别器。 您也可
我想设置一个 UITapGestureRecognizer 以允许用户添加图像作为配置文件。我设置了代码,但是当我触摸图像时,什么也没有发生。代码如下: @IBAction func selezion
现在我有一个功能,如果点击底部文本字段,则整个屏幕向上移动,否则如果点击顶部文本字段,则我不会移动屏幕: func keyboardWillShow(notification: NSNotificat
我正在尝试创建一个利用 UITapGestureRecignizer 来执行转场的按钮。由于某种原因,当我尝试从导航面板按住 Control 键拖动到助理编辑器时,它无法连接。我正在使用以下代码: o
我已经搜索了此问题的解决方案,但找不到任何似乎可以解决我的情况的内容。我从 UITapGestureRecognizer 收到上述异常。 这是简化的代码: import UIKit; class Vi
我正在尝试向 View 添加 2 个 UITapGestureRecognizers,一个用于单击事件,一个用于双击事件。单击识别器按预期工作(自行)。但我似乎无法让双击识别器工作。 已尝试尝试以下属
我的 UITapGestureRecognizer 有问题。我使用这段代码: let gesture = UITapGestureRecognizer(target: self, action: #s
为了做好准备,我有一个 4x5 的 UIImageView 网格,我想在点击时翻转并显示新图像。我想用一个@IBaction 来完成这个任务。我只是在识别点击时引用选定的 UIIMageView 时遇
我的 UIViewController 上有一个 UITapGestureRecognizer。 UIViewController 有一个 UIScrollView,它有一个 UIWebView。现在
我正在使用 UITapGestureRecognizer 这是我的代码: Home.m: - (void)viewDidLoad { [super viewDidLoad]; UITa
我在最低 View (self.view) 上使用 UITapGestureRecognizer 来隐藏我的键盘。 UITapGestureRecognizer *tapHandler = [[UIT
我正在尝试在我的 iOS 应用程序上实现一种“帮助模式”。当用户点击帮助按钮时,UITapGestureRecognizer 会拦截对屏幕的触摸,如果它在控件上,则会出现一个带有帮助信息的小弹出窗口。
我有一个红色的 SCNNode,它以 1/2 的方式悬停在蓝色 SCNNode 上。我需要它们两个的dragEvent,这样当它们被滑动时它们就会移动(效果很好)。问题是我只需要蓝色节点的 tapEv
我的任务是将音频播放器添加到现有的 iPad/iPhone 应用程序中。在过去的两天里,我一直在努力弄清楚为什么我不能让一个简单的点击手势工作。我已经搜索了互联网无济于事。我知道有几个这样的问题已经存
我是一名优秀的程序员,十分优秀!