問題描述
我在 uitextfield
正下方有一個(gè) uitableview
,它在 uitableview 單元格
中填充類似的字符串.項(xiàng)目被填充.然而 didSelectRowAtIndexPath
在長按后被調(diào)用
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:
僅在長按自定義單元格后調(diào)用
My UITableView
(is embedded in UIScrollView)
- didSelectRowAtIndexPath:
only being called after long press on custom cell
我的視圖層次結(jié)構(gòu):
- UIScrollView(外滾動(dòng))
- 其他一些視圖和按鈕
- 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
時(shí)正常工作.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
,請確保設(shè)置了適當(dāng)?shù)募s束.Make sure that you are setting proper constraints if you are using
autolayout
.第二件事是刪除不必要的手勢識(shí)別器
隱式
,這不是必需的.Second thing remove unnecessary gesture recognizer
implicitly
which is not required.默認(rèn)情況下,Tableview 啟用滾動(dòng),因此無需再次將其設(shè)置為 true.(順便說一句,這不會(huì)影響您的問題!!)
Tableview have scroll enable by default so not need to set it true again. (it's not affect your issue btw!!)
所以刪除不必要的配置并進(jìn)行適當(dāng)?shù)脑O(shè)置,我認(rèn)為您的問題將得到解決.
So remove unnecessary configuration and make proper setup and your issue will be solved i think.
這篇關(guān)于長按后調(diào)用 didSelectRowAtIndexPath的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!