长按后调用 didSelectRowAtIndexPath

时间:2022-12-31
本文介绍了长按后调用 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 in UIScrollView.

    推荐答案

    尝试在 scroll view 中添加 uiview 并添加 uiview 比如你的 tableView,textfield,views and buttons 等等.

    Try to add uiview in your scroll view and add every elements in that uiview like your tableView,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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 UIScrollView 上显示大 UIView 的最佳方式是什么? 下一篇:滚动时如何在 UIScrollView 中移动一个方向

相关文章

最新文章