I am creating a series of ImageCheckRows as a SelectableSection, and I would like to set some default values. Essentially each row returns a true/false value, so somewhere there should be a simply method of setting true or false on each row. I tried the row.value but this requires a 'String?'
currentSection! <<< ImageCheckRow<String> { row in
row.tag = "\(tagname)_\(optionKey)"
row.title = optionValue as? String
row.selectableValue = optionKey as? String
if let dvkey = optionKey as? String {
print("dvkey = \(dvkey)")
if let _ = defaultValues?.value(forKey: dvkey) {
print("we found dvkey in the defaultValues dict - try row.select")
row.value = true
}
}
}.cellSetup { cell, _ in
cell.trueImage = UIImage(named: imageChecked)!
cell.falseImage = UIImage(named: imageUnchecked)!
}
I also tried using the function:
row.select()
But this didn't work either.
Then I tried moving it to the cellSetup, but this didn't work either.
Can anyone help me here?
Worked it out myself...
row.value = optionKeyValue as? String
This is a radio button style control, and as I create the row with the default radio button I set the value to the key, however it must be a string representation, even if it is numeric. Who would have guessed!
My first thought was that the radio button control is checked/unchecked, hence it should really be a true/false value.
My second thought was that the radio button control default value would be set against the group, which is a more logical place to set or change the value.
Wrong on both counts.
Related
I use Export/Import localization functionality in Xcode 13.2.1 and it works more or less fine but some strings are not exported in xcloc file, for example texts from function below
func createInitialStepTypes(inContext context: NSManagedObjectContext) {
let names = ["NVA", "NEC", "VA"]
let nvaDesc = "Step with not added value (typically preparing of equipment, exception handling, etc.)."
let necDesc = "Necessary steps but still not adding value (typically system actions like login, manual data entry, etc.)."
let vaDesc = "Step with added value (typically material handling)."
let descs = [nvaDesc, necDesc, vaDesc]
let colors: [Color] = [Color.red, Color.orange, Color.green]
for (i, _) in names.enumerated() {
name = names[i]
desc = descs[i]
color = colors[i]
save(stepTypeID: nil, inContext: context)
}
}
Strings from other functions in the same class like e.g. this one
errMsg = "Step type \(stepType.name!) can't be deleted because it's being used."
are captured correctly. Any idea why?
Thanks.
I'm trying to craft a view based tableView delegate method to alter a column's font IFF its identifier is 'name' and its value matches some global; otherwise the the nib should prevail. I think I have either a noob setup issue or my logic is omitting something.
I have two tables, one view based (tag=0), one cell (tag=1), and both have the same view controller as their delegate. Each tableView's has a unique tag and identifier, an array controller for column value bindings, and each of fits columns has an explicit unique identifier - matching its binding; I had tried omitting this - "the automatic setting" - but this yielded no data!?
So, I added this method, but both tableViews call into it; I would expect only the first. The 2nd table is a detail of the 1st, having its 1st array controller selection.
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let item = ((tableView.dataSource as! NSArrayController).arrangedObjects as! [AnyObject])[row]
var view = tableView.makeView(withIdentifier: tableColumn!.identifier, owner: self)
if view == nil {
Swift.print("tag: \(tableView.tag) ident: \(tableColumn!.identifier.rawValue)")
view = NSTableCellView.init()
view?.identifier = tableColumn?.identifier
}
guard tableView.tag == 0 else { return view }
guard isGlobalPlist, item.name == '<some-global-string>',
let identifier = tableColumn?.identifier,
identifier.rawValue == "name" else { return view }
if let cellView = view as? NSTableCellView {
if tableView.selectedRowIndexes.intersection(IndexSet.init(integer: row)).count > 0 {
cellView.textField?.font = .boldSystemFont(ofSize: -1)
cellView.textField?.textColor = .white
}
else
{
cellView.textField?.font = .systemFont(ofSize: -1)
cellView.textField?.textColor = .blue
}
}
return view
}
Firstly I notice that the method is called for the 2nd table when I wouldn't have expect it, it being a cell based tableView.
Anyway, I do create the cell when nil return, the docs cite that you need just need to matchup the identifiers:
Note that a cell view’s identifier must be the same as its table column’s identifier for bindings to work. If you’re using bindings, it’s recommended that you use the Automatic identifier setting in Interface Builder.
which I do; both tableView's columns are bound (view, or cell) to their respective array controller using column identifier explicitly entered.
Anyway the original intent I was after was for the view based (1st) tableView:
the view controller was controlling a global resource (isGlobalPlist is true)
the row's 'name' value matches a global value value
to the affect 'name' cell shown in distinct color (blue/yellow - or something) depending on whether the row was selected due to selection highlighting, dark mode etc conditions.
So there would be 1 of 4 possibilities
selected row, matching global -> fore:yellow, back:default
selected row, not matching global -> fore:default, back:default
non-selected row, matching global -> fore:blue, back:default
non-selected row, not matching global -> fore:default, back:default
If the target row matched requirements, the coloring needs to vary depending on its inclusion in the tableView's selected indexes.
The setting seems to properly affect initially - selected row and matching value, but then settings seem to bleed across other rows navigated to - so the selection change. At most there should be 1 row's name column with this affect.
I can't tell if my logic or setup is wrong; I suspect I probably need to refresh as I move about ?
Well I gave up on a view based solution but this fills my need; a cell based solution:
func tableView(_ tableView: NSTableView, dataCellFor tableColumn: NSTableColumn?, row: Int) -> NSCell? {
guard let column = tableColumn else { return nil }
let item : AnyObject = ([table0ArrayController,table1ArrayController][tableView.tag]?.arrangedObjects as! [AnyObject])[row]
let cell : NSTextFieldCell = column.dataCell(forRow: row) as! NSTextFieldCell
cell.textColor = .textColor
guard tableView.tag == 0, isGlobalPlist, item.name == '<some-global-string>' else { return cell }
if tableView.selectedRowIndexes.intersection(IndexSet.init(integer: row)).count > 0 {
cell.textColor = .white
}
else
{
cell.textColor = .blue
}
return cell
}
I wanted to call attention to specific row(s) with color, unless row was selected for the 'name' column only.
My TableView is populated with data from a list of objects. The first column is a Boolean value.
Instead of displaying True or False in the cell, I would like to display an image if True and leave the cell empty if it's False.
This is how I populate the TableView:
colStarred.setCellValueFactory(new PropertyValueFactory<>("starred"));
colDate.setCellValueFactory(new PropertyValueFactory<>("date"));
colTime.setCellValueFactory(new PropertyValueFactory<>("time"));
I know that I need to use a custom TableCell and a CellValueFactory but I'm having a hard time wrapping my head around the documentation (I have not used Java factories in the past).
My research has lead to several answers regarding similar situations, but they all seem to deal with just displaying an image in the cell. I have been unable to find a solution for checking a boolean to determine whether an image should be displayed or not.
How do I check the starredProperty of my objects and show an image if it is True?
Thank you for all the help everyone has provided me in the past!
I'll assume the column to be a TableColumn<MyItemClass, Boolean>.
You simply create TableCells that adjust their look according to the item that gets passed to the updateItem method.
In this case we'll use a ImageView as graphic of the cell.
The following images are displayed depending on the item of the cell:
no image if the cell is empty or contains null
imageTrue if the item is true
imageFalse otherwise
You may of course use imageFalse = null for an empty cell when the item is false.
final Image imageTrue = ...
final Image imageFalse = ...
// set cellfactory
colStarred.setCellFactory(col -> new TableCell<MyItemClass, Boolean>() {
private final ImageView imageView = new ImageView();
{
// initialize ImageView + set as graphic
imageView.setFitWidth(20);
imageView.setFitHeight(20);
setGraphic(imageView);
}
#Override
protected void updateItem(Boolean item, boolean empty) {
if (empty || item == null) {
// no image for empty cells
imageView.setImage(null);
} else {
// set image for non-empty cell
imageView.setImage(item ? imageTrue : imageFalse);
}
}
});
What happens when the program is displayed is this:
The TableView creates cells needed to display the items using the cellfactories.
The TableView assigns the items to the cells. These items may be changed multiple times. Cells may also become empty after being filled. When this happens the updateItem methods of the TableCells are called.
I'm trying to populate a textView with the content of an array. For each item in my array i have a flag setting true or false for this item, if its true i copy the content in a var called "nome" to the textview.
I did this with the code below:
for item in lista {
if item.disp == true { //checking if its true
var tempString = "\(item.nome)\n" //concatenate string with the a new line
textView_Lista_Pecas.text! += tempString //set the textView text
}
}
... the string printed must be shown line by line, but as it is a long string, the textView break the line when the string texts gets to the edge of textView.
I tried to enabled the horizontal scrollview to maximize the size of the textView, but only the vertical one is enabled when i check the option.
Anyone could give me a hint on this? I'm using swift and xcode 6.3.1.
Here is what I am trying to do. I have a list that populates a drop down list created by data validation. I then query the data to populate a second list based on the first drop down value. Everything works except I would like to set the first value in the second drop down to be the default value. In other words if I change the value in the first drop down my second drop down now shows an error until I select the drop down and change the value to a correct value. I would like to set it to the first correct value when the first drop down is changed. My reason for this is I dont want someone to forget to change the second drop down and get a value that is not even in the range.
Please help I am new to this kind of thing.
thanks
https://docs.google.com/spreadsheets/d/1U2_0Ku1bCLfDh_v2XyE9aQMSfdYmlVfX_8SKmQay48g/edit?usp=sharing
Here is what I have so far. It works except anytime the sheet is edited the value is reset. I only want it to reset when Cell A2 changes.
function onEdit() {
var ss = SpreadsheetApp.getActive()
var sheet = SpreadsheetApp.getActiveSheet();
// IF(cellContent has changed) then clear B2
// else do nothing.
sheet.getRange('B2').clearContent();
var value = sheet.getRange('H2').getValue();
sheet.getRange('B2').setValue(value);
}
I figured it out and this seems to work just fine.
function onEdit() {
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getActiveCell();
var cellR = cell.getRow();
var cellC = cell.getColumn();
var cellValue = cell.getValue();
var active_spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var value = active_spreadsheet.getRange('H2').getValue();
if (cellR == 2 && cellC == 1) {
sheet.getRange('B2').clearContent();
sheet.getRange('B2').setValue(value);
}
}