Inconsistent NSTextField Cursor (macOS, Swift) - swift

I'm writing a menu bar app that requires a search bar. I did the followind steps:
dragged a menu into the storyboard (like this:
)
created a custom view and added a textfield
Using this line of code to relaced the menu item Search Bar with the custom view:
itemSearch.view = viewSearchBar
The result was not satisfactory. Sometimes, when I move my cursor onto the NSTextField, the result is like this:
which is normal. And in these cases, this is what happens when I click the NSTextField:
However, other times, just relaunching the app without any change of the code, the results (with the cursor hovering above the NSTextField) look like this:
And the result will be like this when I click my mouse:
I am really frustrated by this issue, and after two hours of trying, I just want to know the answer...
Please! any ideas?

Related

XCode 10 adding action to button

I'm trying to make a Cocoa app with buttons that run simple command line scripts.
I can't seem to figure out how to add the action to my button.
I've read some docs that suggest holding down option and dragging the button into controller code but I think they are out of date. Can someone suggest how to get there from this screenshot?
You need to first select your button, then hold the control ⌃ button on your keyboard and then drag that across to your view controller. That will then give you the option of what to name your method etc.
Actually I had the same problem and the root cause was just the drag method. From the descriptions I had assumed that I need to press CTL and then drag while having the left mouse button pressed. This did not work at all (in my environment). Then I noticed that "it works" with the right mouse button. But the result was not correct. (E.g. I could not get "Action"). Finally I found: I have to use the right mouse button only for dragging without holding CTL. Then I got the correct result.

XCode/Swift OSX. Select and Edit Cells in ViewBased NSTableView

Before I ask my OSX related question please allow me to describe a feature in MS Windows.
If I create a Windows application in MS Visual Studio where the application contains a simple DataGrid the user can simply click into a cell, edit the contents and use the keyboard up/down arrow keys to move quickly out of the cell to the next one. keying out of the cell triggers the EndEdit event. Using the up/down arrow keys like that a user can quickly move down a column editing values without pressing Enter or using the mouse.
I'm trying to do the same with OSX XCode/Swift. Using the mouse to click into a cell and edit is no problem. But it seems as though I have to click the cell twice to get it selected for editing and then after editing I have to press enter or click another cell. I can't simply use the up/down arrow keys to key out of the cell.
Is that simply the way OSX works? I mean I'm making an OSX application so I want it to behave like a native application but it just seems like a lot of entering and clicking is required if, for example, the user was going to edit a few cells.
Are there any properties I need to set in the ViewBased TableView?
Sorry about the long email - I hope I've explained it though.
Thanks
Ian
After much head scratching I've got something that appears to work exactly as I want.
myTableView is on an NSViewController.
In the NSViewController's viewDidLoad() I've got this:
super.viewDidLoad();
NSEvent.addLocalMonitorForEventsMatchingMask(NSEventMask.KeyDownMask, handler:{
(event: NSEvent) in
self.myTableView.keyDown(event);
switch(event.keyCode)
{
case 36:
return nil;
case 125:
return nil;
case 126:
return nil;
default:
return event;
}
})
I have to confess I'm not 100% sure but my thoughts were that the default behavior of the tableView is for the up/down arrow keys to move the row selection up or down a row but that doesn't happen when a cell is being edited. When the text cell has edit focus the up/down keys simply shift the cursor to the start/end of the cell (ie move the cursor within the cell). Not the behavior I want so I thought if I could swallow (make nil) those events within the cell then the arrow keypress would bubble up to the tableview and it would do the up/down row select - if you see what I mean.
Anyway - no matter where my thoughts were - this does seem to work exactly as I want and when the edit focus arrives on the next cell it gets instant edit focus. Basically working just like it does in programs such as excel and numbers etc.

Can't move focus from table view to adjoining button on tvOS

I have a single ViewController which contains a Table View on the left and a few labels on the right. Navigating through the table view entries works fine (up/down). Focus is no problem there. Even the related text in the labels is updated just fine using tableView:didUpdateFocusInContext.
The interface looks like this:
However, the button on the right ("Jetzt ansehen") never gets focus. When I use the debugger (as suggested in the official documentation), it doesn't include the button in the focusable area at all:
I really tried to solve this using UIFocusGuide, but I have no real idea how to accomplish that, yet.

Access Menu sub form - No default Tab stop

I have a main form...imagine that...that for most of my users will be the only form they use. Naturally, it contains tabs with sub forms.
I have a navigation sub form on the left side of this form that changes based on the user's rights level. Currently, this sub form is all buttons...and 1 always is selected as the default tab stop for that form.
I don't want to highlight any of them at first...and I can remove the highlight by switching off Tab Stops for all buttons. However, I'm not sure that I want to remove that functionality all together...and it still highlights a button. I'd just like for there to not be a default button highlighted.
As you can see, Add Course is 'selected'. I can't seem to find the correct terminology to search for a way to do this. I tried using a smaller button set behind another button, but since it has the focus, it moves to the front. Using a text field with the same colors as the background shows the cursor in a random, blank area...not visually ideal.
I'm sure that there is someone here clever enough to have this figured out. Please enlighten me. I don't care if this can be handled in VBA code or through design view.
"Focus" is the word you're looking for - you don't want any visible control to have the focus when opening the form.
The easiest method is an invisible button: create a button with Transparent = True, and an empty OnClick (i.e. the button does nothing, even when accidentally clicked).
Move this button to the top in the Tab Order, so it has the focus when opening the form.
But if your users use TAB to walk through the buttons, there will be one position where the focus disappears (when circling around from the last to first control). I don't know if it will confuse them.
Create a button on the main form itself.
Named is cmdDummyButton with the following GotFocus event code.
Set the tab order property to 0 (ie first)
Make the button transparent.
This will cause no control on the form to have the focus when it starts up.
Private Sub cmdDummyButton_GotFocus()
Static IveHadFocusAlready As Boolean
If Not IveHadFocusAlready Then
Me.cmdDummyButton.Enabled = False
IveHadFocusAlready = True
End If
End Sub
Sweet.

UIButton doesn't display properly

I added a UIButton to a view in my application. Its a custom button, with two different images for its default and highlighted state. I have 2 other buttons on the view that are very similar but provide different functions.
However, my latest button won't display at all. I've clean the project as suggested in another question and it still won't display. Whats doubly weird though is that if I click the area of the view where the button should be, the IBAction is called and the UITextFields are cleared as if the button was there. Its as if the button is being created without its graphics being displayed.
Does anyone know what might be happening here? The button looks as it should in IB.
Thanks, Jack
Go to the Organizer window, select the Projects tab, select your project in the list and then delete the derived data folder by choosing "Delete…" in the window.
If that doesn't work, check if the images are included in the target. Select the image files and look in the info editor (the Files tab — the left one) if it's added to the target.
Hope that helps.