didSelectRowAtIndexPath called after long press(长按后调用 didSelectRowAtIndexPath)
问题描述
我在 uitextfield
正下方有一个 uitableview
,它在 uitableview 单元格
中填充类似的字符串.项目被填充.然而 didSelectRowAtIndexPath
在长按后被调用
I have a uitableview
right below a uitextfield
that populates similar strings in a uitableview cell
.
The items get populated. However the didSelectRowAtIndexPath
gets called after long press
我的 UITableView
(嵌入在 UIScrollView 中)- didSelectRowAtIndexPath:
仅在长按自定义单元格后调用
My UITableView
(is embedded in UIScrollView)
- didSelectRowAtIndexPath:
only being called after long press on custom cell
我的视图层次结构:
- UIScrollView(外滚动)
- 其他一些视图和按钮
- UItex 字段
- UITableView(表格视图)
我的代码
class MyViewController: BaseViewController , UITextFieldDelegate , UITableViewDelegate , UITableViewDataSource , UIGestureRecognizerDelegate { @IBOutlet weak var autocompleteTableView: UITableView! var pastUrls = ["Men", "Women", "Cats", "Dogs", "Children","aaaaaaaaa","aaaaaaaaaaaaaaaaaaa","aaaaaaaaa","a","aa","aaa"] var autocompleteUrls = [String]() @IBOutlet weak var image_view_seacrh_ifsc: UIImageView! @IBOutlet weak var scrollView: UIScrollView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. self.scrollView.panGestureRecognizer.delaysTouchesBegan = true autocompleteTableView.delegate = self autocompleteTableView.dataSource = self autocompleteTableView.scrollEnabled = true autocompleteTableView.alwaysBounceVertical = false autocompleteTableView.allowsSelection = true autocompleteTableView.allowsSelectionDuringEditing = true autocompleteTableView.hidden = true super.hideKeyboard() super.showNavigationBarBackButton() let gesture_search_ifsc = UITapGestureRecognizer(target: self, action: "action_Search_Ifsc:") gesture_search_ifsc.delegate = self gesture_search_ifsc.numberOfTapsRequired = 1 image_view_seacrh_ifsc.userInteractionEnabled = true image_view_seacrh_ifsc.addGestureRecognizer(gesture_search_ifsc) } func searchAutocompleteEntriesWithSubstring(substring: String) { autocompleteUrls.removeAll(keepCapacity: false) for curString in pastUrls { var myString:NSString! = curString as NSString var substringRange :NSRange! = myString.rangeOfString(substring) if (substringRange.location == 0) { autocompleteUrls.append(curString) } } autocompleteTableView.reloadData() //autocompleteTableView.hidden = false } func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return autocompleteUrls.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell: AutoBankCell = tableView.dequeueReusableCellWithIdentifier("AutoBankCell") as! AutoBankCell cell.label.text = self.autocompleteUrls[indexPath.row] //cell.lbl.text = self.autocompleteUrls[indexPath.row] return cell } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let selectedCell : UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)! self.bank_name.text = self.autocompleteUrls[indexPath.row] self.autocompleteTableView.scrollEnabled = true self.autocompleteTableView.hidden = true } }
我的
UItableView
被填充并在未嵌入UIScrollView
时正常工作.My
UItableView
gets populated and works properly when not embedded inUIScrollView
.推荐答案
尝试在
scroll view
中添加uiview
并添加uiview
比如你的tableView,textfield,views and buttons
等等.Try to add
uiview
in yourscroll view
and add every elements in thatuiview
like yourtableView,textfield,views and buttons
etc.因此,该视图用作容器视图.
So, that view works as container view.
如果您使用
autolayout
,请确保设置了适当的约束.Make sure that you are setting proper constraints if you are using
autolayout
.第二件事是删除不必要的手势识别器
隐式
,这不是必需的.Second thing remove unnecessary gesture recognizer
implicitly
which is not required.默认情况下,Tableview 启用滚动,因此无需再次将其设置为 true.(顺便说一句,这不会影响您的问题!!)
Tableview have scroll enable by default so not need to set it true again. (it's not affect your issue btw!!)
所以删除不必要的配置并进行适当的设置,我认为您的问题将得到解决.
So remove unnecessary configuration and make proper setup and your issue will be solved i think.
这篇关于长按后调用 didSelectRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:长按后调用 didSelectRowAtIndexPath
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01