Scroll UITableView up when keyboard appears in swift [duplicate] - ios

This question already has answers here:
How can I make a UITextField move up when the keyboard is present - on starting to edit?
(98 answers)
Closed 7 years ago.
I have a UITableView with 7 cells and every cell has a text field inside it. When the keyboard appears it hides the last cell so it is quite difficult to see what has been input until and unless the keyboard disappears.
Can anyone guide me how I can scroll this UITableview up when the keyboard appears so I don't have this problem?

Try this one:
func textFieldDidBeginEditing(textField: UITextField) {
tableView.setContentOffset(CGPointMake(0, textField.center.y-60), animated: true)
}

Use thiese simple set of classes https://github.com/michaeltyson/TPKeyboardAvoiding
How to use:
For use with UITableViewController classes, drop TPKeyboardAvoidingTableView.m and TPKeyboardAvoidingTableView.h into your project, and make your UITableView a TPKeyboardAvoidingTableView in the xib. If you're not using a xib with your controller, I know of no easy way to make its UITableView a custom class: The path of least resistance is to create a xib for it.

Related

SwiftUI: Show TextField Keyboard as soon as View loads? [duplicate]

This question already has answers here:
SwiftUI: How to make TextField become first responder?
(23 answers)
Closed 2 years ago.
I have a screen in my app that contains a TextField.
I want the keyboard for the TextField to be displayed on default (i.e. as soon as the user navigates to the view, the keyboard should already be up).
How is this accomplished?
You have to just make an outlet from textfield and follow the following code.
https://stackoverflow.com/a/49815898/5086658

How can I build the following UI item? [duplicate]

This question already has answers here:
How to have one static cell in a dynamic tableview?
(3 answers)
Closed 3 years ago.
I'm trying to make a view similar to the one on the screenshot.
The question is what is the first element(the one with label and chevron)
When I tap on it, it behaves like a table cell(on the screenshot I captured it in tapped state). Thank you!
UPDATE
I ended up creating 2 sections and then checked for index
Looks to me exactly like a standard UITableView cell, with cell.accessoryType = .disclosureIndicator and the background color etc. changed of course.
Honestly looks like the standard table view cell, but you could easily implement this with a custom view (NIB) as well.
You can build this view with UITableViewDelegate like this:
Make a button in the cell and set this image to the button.
Set yourButton.isHidden = true in cellForRowAtIndexPath
Set yourButton.isHidden = false in didSelectRowAtIndextPath
That's it.

Swift 3 Show the 'Copy' popup on UITableViewCells when select cell of table like Contaccts app [duplicate]

This question already has an answer here:
How to show "Copy" menu for a table cell?
(1 answer)
Closed 6 years ago.
How to show popup "copy" when select cell of table ?
You can't do it the normal way with UILabel. If you still want to do it, use UITextField instead and disable editing (It will act as label and allow text selection). If you want to use UILabel anyways, you might want to look into UILongGestureRecognizer and UIPasteBoard. Add gesture to the label and on its delegate method, copy text to paste board.

How To Detect When The Minus Button in a UITableViewCell Was Tapped During Editing? [duplicate]

This question already has answers here:
UITableView : detecting click on '-' button in edit mode
(2 answers)
Closed 9 years ago.
I have a UITableView with editing enabled. I'd like to hide specific elements of a cell when the minus button is tapped, but can't find a way to detect that the minus button was tapped. Anyone know how to detect this?
You will have to subclass UITableViewCell, and implement the method willTransitionToState

Adding UITableViewCell with a UITextField upon pressing a UIBarButtonItem

I am very new to IOS development and Objective-C as i have just come from a mostly Java background. I have quite frankly searched everywhere on the web to find the answer to my question but nobody as it seems can give a clear concise answer on how to do this so anything would be VERY much appreciated!
So here is what i am trying to do. I have a UITableView and a UIToolBar below it with a UIBarButtonItem. What i want to do is be able to press the BarButtonItem and then have a new TableViewCell with a text field in it be created and placed at the top of the TableView that has a unique tag so that i can parse through the text fields later and retrieve the text to store into a mutable array.
Any help would be really awesome so thank you in advance, i would really like to get this working! If you have any questions on the code i have or more details on what i am asking please ask away!
Well there are plenty of resources on how to add TableViews, Toolbars, etc... Here's an overview of what you'll want to do.
In your ViewController's view, add a UITableView to it, but remember you want to leave space in your ViewController's view for the toolbar at the bottom of the screen. So set the tableView.frame accordingly.
Look up how to add a UIToolbar (http://stackoverflow.com/a/7712240/1457445 is a good start)
Then how to add a UIBarButtonItem (http://stackoverflow.com/questions/5383906/how-to-add-uibarbuttonitem-in-uitoolbar-in-code)
As for adding the textView in the UITableViewCell, you simply call [tableView.contentView addSubview:yourTextView];
Again, there is plenty of help out there for customizing UITableViewCells (http://stackoverflow.com/questions/4238760/how-to-make-a-uitableviewcell-with-a-uitextview-inside-that-dynamically-adjust)
And to top it off, you'll need to figure out how to add the textview cell to the table - another great SO post (http://stackoverflow.com/questions/5824998/uitableview-adding-cells-dynamically)
The simplest way is put your UITextField on UITableView header when UIToolbar button item touched. The simplest way is put your UITextField on UITableView header when UIToolbar button item touched. After user done on UITextField then update your NSMutableArray reload data of UITableView and remove header on UITableView.

Resources