disable tableview with all elements - swift

I working with swift 4 for macOS and I have a NSButton, which should disable my NSTableView with all elements (textfields, buttons, ...)
In the IBAction of my button I have this code lines:
myTableView.deselectAll(nil)
myTableView.isEnabled = false
This works good, but I found a little "bug".
If I select a textfield of my tableview (edit mode on)
and press after that my button, the tableview will be disabled and all selected rows will unselect, but I can edit the content of my textfield without a problem, because the "edit mode" is still on.
Must I disable all my textfields in the tableview manually or is there an elegant trick?

You can make NSTextField lose responder with
view.window?.makeFirstResponder(view.window)
This should do the trick.

Related

Best way to disable UITextField "up" and "down" arrows

My ViewController has two UITextFields, so by default the keyboard toolbar has these ^ and v buttons. I don't want the user to be able to switch between the textfields with these buttons so i'd like to hide them if possible. I've tried disabling the inactive textfield but this messes with the firstResponder methods so if possible I'd like a different solution. Is there any way to just hide these buttons from the default toolbar?
]1
You could try to set an empty inputAccessoryView of this textField. Or simply:
myTextView.inputAccessoryView = nil
to remove the whole accessoryView.

edit Textfield with a little delay

I working with swift 4 for macOS and have a NSTableView with custom Cells.
In my row are two textfields (style: borderless and no background color)
Normally, you click on a textfield and it will directly be editable.
In my case, you click on the textfield and after a short delay it will be editable.
But I don't understand why is there such a delay.
Have anybody an idea?
Better Example
My tableview with Custom Cell View (delay problem)
Another tableview without Custom Cell View (no delay problem)
I hope you can see the difference. I do both situations with the same steps.
Select Row (click)
Select textfield (click)
Seems like you’re selecting the table view cell first. Try tableView.allowsSelection = false

Prevent keyboard from moving textview in UITableView

I have 2 cells in a group in a tableview, the first has a textview in it, (2 lines max). When the user selects the textview, the keyboard appears and moves the textview up from under the keyboard. the second cell only appears when the textview has focus.
However the second cell is still hidden by the keyboard, I have tried to the various methods that scroll the tableview, but the result is always jerky, with the table moving up and down rapidly. Probably because its inserting a row, scrolling up for the keyboard and me trying to make it scroll up even more all at once.
How can I prevent the keyboard from moving scrolling the table view at all, so that I can do the scrolling myself exactly how I want it, and avoid the ugly fight between the two methods.
Did you try this method by setting scroll position to UITableViewScrollPositionTop ,if this not work ,just make your second cell that with textfield :)
- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
Use a UITableViewController instead a UIViewController (for the ViewController where your UITableView is placed). That will solve the scrolling issue.
If not possible, you have to scroll by your self (pain in the ass).
See: Making a UITableView scroll when text field is selected

Iphone custom cell keyboard overlaps

i have a TableView with custom cells that i have built with Interface Builder.
Inside the cell, i have a label and a text field. But when i click on the text field to write, the keyboard overlaps the text field and i can't see what i am writing.
How can i avoid this?
Thanks
You have to resize the view containing the tableview when keyboard is shown. The way you can do is discussed here,
How to make a UITextField move up when keyboard is present?
You can search in Stackoverflow more on 'iphone keyboard hides textview'.
after resizing view, you can scroll table to the current cell too.

Editing a table like iPhone Mail

The iPhone Mail application has an edit button in the navigation bar. Tapping that button shows a delete button in the toolbar and shows checkbox controls in the table cells. Tapping one or more checkboxes then tapping the delete button causes the checked messages to be deleted.
How can I add similar functionality to my own code?
Here's a screenshot of the effect I'm looking for:
screenshot of spam folder with some messages checked http://www.freeimagehosting.net/uploads/add199aa62.png
UINavigationBar has a UINavigationItem with a leftBarButtonItem and a rightBarButtonItem.
To set your edit button you init a bar button item with the style: UIBarButtonSystemItemEdit.
Follow the delete button example here:
http://dragonforged.com/devblog/?p=34
#DavidSowsy's answer only shows how to draw a red button.
For those actually interested in selecting multiple rows in a UITableView, I have found 2 ways to do it:
The easy way that involves undocumented APIs and will probably make your app crash in the next
OS update.
The proper one, that is a bit more work but works well and you won't have to think about it again.
For my project, I chose the latter.