I'm using this component:
https://github.com/Darkseal/DownPicker
let persons = ["Architect", "Designer", "Chef", "Doctor"]
self.personDownPicker = DownPicker(textField: self.personTextField, withData:persons)
And it's displaying the data correctly, but, how I can have an option selected by default?
Just looking into the source code, the DownPicker instance has a selectedIndex property. Set it to the index of the selected item.
Related
I have a couple of UIKit pop-up menu buttons with identical menu items on the same screen in a Swift app. The buttons are built by calling a function that uses an array of strings to create the list of menu items.
The problem is that depending on the button's vertical position on the screen, the menu items may appear in the order specified by the function, or reversed. If the button is in the upper half of the screen, the menu items are listed in the correct order. If the button is in the lower half of the screen the menu items are listed in reverse order.
I would prefer the menu items to appear in the same order regardless of the button's position on the screen. I could check the button location and have the menu creation function reverse the order, but that seems kind of clunky. I am hoping there's a cleaner way to override this behaviour.
The code and array used to create the button menus:
let buttonMenuItems = ["Spring","Summer","Autumn","Winter"]
func createAttributeMenu(menuNumber: Int)->UIMenu {
var menuActions: [UIAction] = []
for attribute in buttonMenuItems {
let item = UIAction(title: attribute) { action in
self.updateMenu(menuID: menuNumber, selected: attribute)
}
menuActions.append(item)
}
return UIMenu(title: "", children: menuActions)
}
The result is this:
Versions I'm using now in testing: Xcode 14.1, iOS 16.1, but I have seen this behaviour on earlier versions as well. (back to iOS 14.x)
Starting with iOS 16, there is a .preferredMenuElementOrder property that can be set on the button:
case automatic
A constant that allows the system to choose an ordering strategy according to the current context.
case priority
A constant that displays menu elements according to their priority.
case fixed
A constant that displays menu elements in a fixed order.
Best I can tell (as with many Apple definitions), there is no difference between .automatic and .priority.
From the .priority docs page:
Discussion
This ordering strategy displays the first menu element in the UIMenu closest to the location of the user interaction.
So, we get "reversed" order based on the position of the menu relative to the button.
To keep your defined order:
buttonNearTop.menu = createAttributeMenu(menuNumber: 1)
buttonNearBottom.menu = createAttributeMenu(menuNumber: 2)
if #available(iOS 16.0, *) {
buttonNearBottom.preferredMenuElementOrder = .fixed
buttonNearTop.preferredMenuElementOrder = .fixed
} else {
// out of luck... you get Apple's "priority" ordering
}
I have an app with two combo boxes in the same view that is both loaded from an SQLite database. If the user makes a selection in combo box 1, I want to fire a method to restrict the values in combo box 2.
I think I need comboBoxSelectionDidChange function, but I don't know how to tell whether the function has been fired by a selection in combo box 1 or 2?
Have looked at the function parameters but can't see how I can tell which combo box fired the function?
The notification contains an object which represents the NSComboBox instance.
If you have created an NSComboBox outlet
#IBOutlet weak var firstComboBox : NSComboBox!
you can compare the instance with the notification object
func comboBoxSelectionDidChange(_ notification: Notification) {
let comboBox = notification.object as! NSComboBox
if comboBox == firstComboBox {
// do something with firstComboBox
} else {
// it's another comboBox
}
}
The solution for ascertaining which combobox fired the selectionDidChange method worked fine. One thing I did learn though was that the method is fired before .stringValue for the new selection is updated. I wanted to use the new .stringValue in the selectionDidChange method but discovered the previous .stringValue.
The way I got around this was to use the indexOfSelectedItem which is updated before the selectionDidChange method is fired.
So my code became
//In order to be able to restrict the contacts available when a company is selected use the comboboSelectionDidChange function
func comboBoxSelectionDidChange(_ notification: Notification) {
//Define a constant combobox that takes the notification object and casts it as an NSCombobox
let combobox = notification.object as! NSComboBox
//Can now test on the combobox object because we only want to do something if cmbCompany selection changes
if combobox == cmbCompany {
//The issue with comboboSelectionDidChange function is that the method is fired before the .stringValue is updated. So using .stringValue wont work as it will use the .stringValue from previous selected item. Therefore use index of selected item as this is updated before the comboboSelectionDidChange function is fired
//Define index which is the index of the newly selected item
let index = cmbCompany.indexOfSelectedItem
//Because the compIndex index will be the same as the index of the selected item we can get the newly selected company from the compIndex which is used to populate the cmbCombobox
let company = compIndex[index]
//Get the idCompany from combobox selection passing in the company from the new selection
idcom = (delegate as! ViewController).getPrimaryKeyComp(company: company)
//Call the function to reload the contIndex with only contacts for the company selected
contIndex = (delegate as!ViewController).getContactForCompany(ic: idcom)
cmbContact.reloadData()
}
}
I want to hide the "top" part of all connector labels of a diagram. For this, I tried to set up a script, but it currently hides ALL labels (also the "bottom" labels which I want to preserve):
// Get a reference to the current diagram
var currentDiagram as EA.Diagram;
currentDiagram = Repository.GetCurrentDiagram();
if (currentDiagram != null)
{
for (var i = 0; i < currentDiagram.DiagramLinks.Count; i++)
{
var currentDiagramLink as EA.DiagramLink;
currentDiagramLink = currentDiagram.DiagramLinks.GetAt(i);
currentDiagramLink.Geometry = currentDiagramLink.Geometry
.replace(/HDN=0/g, "HDN=1")
.replace(/LLT=;/, "LLT=HDN=1;")
.replace(/LRT=;/, "LRT=HDN=1;");
if (!currentDiagramLink.Update())
{
Session.Output(currentDiagramLink.GetLastError());
}
}
}
When I hide only the top labels manually (context menu of a connector/Visibility/Set Label Visibility), the Geometry property of the DiagramLinks remains unchanged, so I guess the detailed label visibility information must be contained somewhere else in the model.
Does anyone know how to change my script?
Thanks in advance!
EDIT:
The dialog for editing the detailed label visibility looks as follows:
My goal is unchecking the "top label" checkboxes programmatically.
In the Geometry attribute you will find a partial string like
LLT=CX=36:CY=13:OX=0:OY=0:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=1:DIR=0:ROT=0;
So in between LLT and the next semi-colon you need to locate the HDN=0 and replace that with HDN=1. A simple global change like above wont work. You need a wild card like in the regex LLT=([^;]+); to work correctly.
I have used a sap.m.SearchField in(SAPUI5),
Now I want to set one of the suggestion item as selected, I mean I want to set a default value to the search field.
How to set selected value in sap.m.SearchField?
While defining SearchField itself you can set the value.
var oSearchField = new sap.m.SearchField({
value: "samplePreText"
});
If you plan to change on some event:
oSearchField.setValue("samplePreText");
I have a SelectItem object which has a few items. I set a value MAP with:
organizations[0] = "A";
organizations[0] = "B";
selectItem.setValueMap(organizations);
When displayed, the combo box is showing "A" as selected item. Then, I need to programatically select value "B" and select this on the current SelectItem object. I've been looking all over the place with no avail.
Anyone?
If you want any option of selectItem to be manually selected, then you should try following:
selectItem.setValue("B");
After doing this when you open the picklist of the selectItem, value "B" will be highlighted.