IOS Double-clicking on a cell element in a UITableView will not scroll

I have a UITableView that contains a UITextField in each cell
When I click on a UITextField in a cell, the keyboard will show and close my cell. So I move my cell to the top with.

 - (void)keyboardWasShown:(NSNotification*)aNotification { CGPoint scrollPoint = CGPointMake(0, self.activeInputView.frame.origin.y); [self.tableView setContentOffset:scrollPoint animated:YES]; } 

If I use one click for each cell, my application works fine.
However, I use double-clicking on each cell (this means that I click on it 2 times very quickly), my cell will stop scrolling up.

+5
source share
7 answers

In this line

CGPoint scrollPoint = CGPointMake(0, self.activeInputView.frame.origin.y);

there may be 2 errors.

First, you need to make sure that the inputView you captured is the desired view. Secondly, you must convert the selected point to the correct representation using the appropriate method.

See link: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/doc/uid/TP40006816-CH3-SW52

Further research requires more context.

+3
source

TPKeyboardAvoiding seems like a solution.

+2
source

Are you sure scrollPoint is correct?

I just created a sample project with a fixed offset, and everything works fine. The table view scrolls up after a single and double click on the UITextField specific UITableViewCell .

 - (void)keyboardDidShow:(NSNotification *)notification { CGPoint point = CGPointMake(0.0, 30.0); [self.tableView setContentOffset:point animated:YES]; } 
+2
source

instead of doing code to manually adjust the tableview frame, Let me give you a suggestion, you can use the IQKeyboardManager, whose package is available in cocoapods and it will cope with clicking on the cell text field, the table will be scrolled automatically.

+1
source

Try using the third-party IQKeyboardManager library, this will help you solve this problem.

https://github.com/hackiftekhar/IQKeyboardManager

Replace the following code in the AppDelegate.m file and you do not need to use the scrollview method to process the keyboard: -

 @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[IQKeyboardManager sharedManager] setEnable:YES]; [self.window makeKeyAndVisible]; return YES; } 
+1
source

Has a separate class created a UITableViewCell?

I believe that when you view your UITableView, your user interface freezes or when you insert your UITableView twice, stop responding, or take time to respond.

+1
source

Here is a working example. You use your scroll view properties, Inset and scrollIndicatorInsets, to prevent the keyboard from appearing when it appears. You must register to be notified of the keyboard. Use the information in notifications to determine the size of the keyboard - you never know what it will be.

Using content pasting is the right way to handle this for scrolling. If you later need to scroll the edit line in the view, use UITableView.scrollToRowAtIndexPath (_ :, atScrollPosition :, animated :)

Note that he is doing the right thing when the user hides / shows the completion panel.

 import UIKit import CoreGraphics // our Cell class class Cell : UITableViewCell { // cell reuse identifier for table view static let Identifier = "Cell" // the object the cell represents/displays. Could be anything you like var value:AnyObject? { didSet { // update our text field when our cell value is set. self.textField.text = value as? String } } // use a text field to display our contents, since that allows editing and showing the keyboard lazy var textField:UITextField = { let textField = UITextField() self.contentView.addSubview( textField ) return textField }() override func layoutSubviews() { super.layoutSubviews() self.textField.frame = contentView.bounds.insetBy(dx: 20, dy: 4 ) } } // table view data source class class DataSource : NSObject, UITableViewDataSource { var numberOfRows:Int { return items.count } let items = [ "Seoul", "São Paulo", "Bombay", "Jakarta", "Karachi", "Moskva", "Istanbul", "Mexico", "Shanghai", "Tokyo", "New" York, "Bangkok", "Beijing", "Delhi", "London", "Hong Kong", "Cairo", "Tehran", "Bogota", "Bandung", "Tianjin", "Lima", "Rio de Janeiro", "Lahore", "Bogor", "Santiago", "St Petersburg", "Shenyang", "Calcutta", "Wuhan" ] func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return numberOfRows } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier( Cell.Identifier ) as? Cell ?? Cell() cell.value = items[ indexPath.row ] return cell } } class ViewController : UIViewController { override func viewDidLoad() { super.viewDidLoad() // register for notifications when the keyboard appears: NSNotificationCenter.defaultCenter().addObserver( self, selector: "keyboardWillShow:", name: UIKeyboardWillChangeFrameNotification, object: nil) } override func viewDidLayoutSubviews() { tableView.frame = view.bounds } lazy var tableView:UITableView = { let tableView = UITableView() self.view.addSubview( tableView ) tableView.dataSource = self.dataSource tableView.delegate = self return tableView }() lazy var dataSource : DataSource = DataSource() // Handle keyboard frame changes here. // Use the CGRect stored in the notification to determine what part of the screen the keyboard will cover. // Adjust our table view contentInset and scrollIndicatorInsets properties so that the table view content avoids the part of the screen covered by the keyboard @objc func keyboardWillShow( note:NSNotification ) { // read the CGRect from the notification (if any) if let newFrame = (note.userInfo?[ UIKeyboardFrameEndUserInfoKey ] as? NSValue)?.CGRectValue() { let insets = UIEdgeInsetsMake( 0, 0, newFrame.height, 0 ) tableView.contentInset = insets tableView.scrollIndicatorInsets = insets } } } // need to conform to UITableViewDelegate protocol since we are the table view delegate extension ViewController : UITableViewDelegate { } // App set up stuff here: @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { lazy var window:UIWindow? = UIWindow() func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { window!.rootViewController = ViewController() window!.makeKeyAndVisible() return true } } 
0
source

Source: https://habr.com/ru/post/1241478/


All Articles