NSTableView get what cell is being edited with keyboard - swift

When I click with the mouse I can get the cell position with myTableView.clickedRow and myTableView.clickedColumn.
However if I click on the first cell and then I press "Tab" key on my keyboard, the selection will stay on row = 0 and column = 0.
Is there a way to track the row and column index when changing cell with keyboard ?

When a text field in a cell is focused then the first responder is the field editor of the text field. Use row(for:) and column(for:) of NSTableView to get the row and column.
if let view = window.firstResponder as? NSView {
let column = tableView.column(for: view)
let row = tableView.row(for: view)
}

Related

Accessibility Text Size affecting alignment in TableViewCell

When I change the text font size in the accessibility, one of the Table View Cell's title becomes left aligned instead of center aligned.
When turned off:
the table view cell button shows the text as it should (centered)
However, when the accessibility text size is set larger, like this:
The table view row cell shows title text of button left aligned:
I am using XLForm to create these buttons as rows with the XLFormRowDescriptor of XLFormRowDescriptorTypeImageButton
This is how I am defining this row:
let row = XLFormRowDescriptor(tag: FormTags.SubmitButton.rawValue, rowType: XLFormRowDescriptorTypeImageButton, title: "submit".localization())
styleRow(row: row)
configureImageRow(row: row, bgImage: UIImage(named: "greenButton")!, selectedBgImage: UIImage(named: "greenButton-pressed")!)
row.cellConfig["textLabel.textColor"] = UIColor.white
row.cellConfig["textLabel.numberOfLines"] = 1
row.cellConfig["textLabel.adjustsFontForContentSizeCategory"] = false
row.cellConfig["textLabel.textAlignment"] = NSTextAlignment.center.rawValue
row.cellStyle = UITableViewCell.CellStyle.default
section.addFormRow(row)

How can I skip the first cell in a NSCollectionView?

How can NSCollectionView items begin at the second cell and leave the first cell empty? (View Example)
Ugly easy way:
Just disable user interaction in the first cell and hide it.
view.isHidden = true
view.isUserInteractionEnabled = false
Correct way:
Register a new invisible cell class with the NSCollectionView and return in just on the first row.

UIBarButton Click to swap tableview cell UI values using Swift?

My scenario, I am having single tableview and single row with custom tableview cell. Here, Only one row I have, within this row I am having stack view with two segments.
First stack segment I am having one Imageview, label and textview and second stack segment I am having imageview, label and textview. I am assigning values from User-default for those UI elements but initially user default may have change to empty on that time default values I am assinging based on some validation.
Now, Barbutton click to Swap the values From (first cell values to second UI) and To (second cell values to first UI). How to do this?
func switchlanglogic(toData: String){
// From fromSessionLanguageName UI values Swap to To UI
let fromSessionLanguageID = "\(UserDefaults.standard.string(forKey: “fromLanguageID") ?? "")"
let fromSessionLanguageName = "\(UserDefaults.standard.string(forKey: “fromLanguageName") ?? "")"
// To toSessionLanguageName UI values Swap to From UI
let toSessionLanguageID = "\(UserDefaults.standard.string(forKey: "toLanguageID") ?? "")"
let toSessionLanguageName = "\(UserDefaults.standard.string(forKey: "toLanguageName") ?? "")"
}

How to autofill the right textfield

I need to autocomplete textfields from tableview. How can i select the right textfield(where i am writing at this moment)?
code is here
If I understand correctly you have two UITextFields and a UITableView and when you tap on a cell in the table view you want to put it's text into whichever text field has your input focus.
Try this:
if firstTextField.isFirstResponder {
firstTextField.text = selectedCell.textLabel.text
}
if secondTextField.isFirstResponder {
secondTextField.text = selectedCell.textLabel.text
}
The isFirstResponder method tells you if the control has the current focus and only one of them can.

UIButton focus in UITableView

I am trying to understand how the focus is working when I have button inside Table.
The goal is to create a table view with custom cell, that has the same size as the table view size ( I want to see only one cell at the time ). When the button is getting focused, I want to scroll ( the table view is doing it automatically ), to the next cell and to see only the next cell.
I made sure that the button will be in focus and not table view cell, by override this method in the Table cell:
override var canBecomeFocused: Bool{
return false
}
The button is focused and when I am swipe up/down, the focus is moving between the buttons and not the Table it self ( great success ) ... BUT, the table view is being scrolling automatically, and I want to understand why is some cases ( when the Table and Table Cell are bigger then 360 pixel ) it's scrolling to the next cell and I can see only the next cell ( the table view and the cell in the same size ) , and sometimes ( when the Table and Cell are Smaller then 360 pixel ) the table view scrolling just a little bit, until the next cell is showing only the button ( meaning the cell is not fully shown )
So , I have:
Cell and table view cell size are Greater then 360, we can see that when the button is focused, the table view scrolling to the center of the cell, and we can see only 1 cell:
Cell and table view cell size is Smaller then 360, we can see that when the button is focused, the table view scrolling to some point, when the button is shown
FYI: I think the size of the button is not effecting the scroll, only the table view and table view cell size is effect the scrolling.
Some one? any idea ?
This is the test Project: in order to see it better please change the table view size and the cell size to be smaller then 360, and make sure the UIButton is centered: Project
You can put those methods in UITableViewCell's subclass. see
override var preferredFocusEnvironments: [UIFocusEnvironment]{
// Condition
}
override func shouldUpdateFocus(in context: UIFocusUpdateContext) -> Bool {
// Condition
}
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
// Condition
}
you can see more at this link: enter link description here