Update NSTouchBar on the fly to add/remove items programmatically
Four ideas:
- Try changing your touch bar's
defaultItemIdentifiers
to the set of item identifiers that should be shown. Note that this would be problematic if the user has customized the touch bar, but I think swapping items on-demand and customizing the touch bar doesn't go well together anyway. This also has the advantage that you don't need to return nil intouchBar(:makeItemForIdentifier:)
. Calling
makeTouchBar()
will create a newNSTouchBar
instance, but not change thetouchBar
property. Try something likeviewController.touchBar = viewController.makeTouchBar()
or
viewController.touchBar = nil
Set the
touchBar
property on theNSTableRowView
that should show extra items when selected, and make sure to include theotherItemsProxy
in yourdefaultItemIdentifiers
. As the contents of the touch bar are comprised of all elements in the responder chain, this might include thetouchBar
property of the table row (provided it can become first responder).Are you sure that these items should be hidden when the row is not selected? Consider disabling them instead (e.g. by setting the
enabled
property of the buttons they contain tofalse
).
Hide NSTouchBar button
I found the answer!
Just write:
<button_name>.isHidden = true
or if you want to disable and not hide:
<button_name>.isEnabled = false
In my case I had button that called "submitButton" so I wrote:
submitButton.isHidden = true
and when I wanted it to appear I wrote:
submitButton.isHidden = false
Knowing when NSPopoverTouchBarItem will show its collapsed view
The docs were not too clear, but subclassing NSPopoverTouchBarItem
gives you -(void)showPopover:(id)sender
and -(void)dismissPopover:(id)sender
.
You can then define a delegate method to tell the parent class that this popover did show.
-(void)showPopover:(id)sender {
[super showPopover:sender];
[self.delegate touchPopoverDidShow];
}
Related Topics
Swift Package Manager Unable to Compile Ncurses Installed Through Homebrew
Encoding Swift String as Escaped Unicode
Error: Extraneous Argument Label 'No1:' in Call
Why Do Two Distinct Array Literals Equal Each Other in Swift
How to Wait for Http Requests to Finish
Instance Member Cannot Be Used on Type | Closures
Delegate Must Respond to Locationmanager:Didupdatelocations Swift Eroor
Exc_Bad_Instruction Happens When Using Dispatch_Get_Global_Queue on iOS 7(Swift)
Name Convention for Unwrapped Value in Swift
Passing Data from Simple Nsview to Swiftui View
Why Use Float(Arc4Random())/0Xffffffff Instead of Drand()
Can Not Cast Value of Type Nstaggedpointerstring to Nsdictionary
How to Place Uisearchcontroller to the Navigationtitle and How to Enable and Disable It by Button
Swift 4: Validating Credit Card Expiration Date
Swift Error: 'Sequence' Requires the Types 'T' and 'Arrayslice<T>' Be Equivalent
Lottieanimationview Size Won't Change/Is Too Small (Ios/Swift)