The question: Is it possible to have a tableView delegate access a variable … ?
The applications sample test code is trying to do the following:
1. The application is trying to make the first column number (a variable), requested by the applications main viewController, visibly stand out in the secondary viewControllers tableView with a large bold different colour font.
The application code:
1. The applications main viewController (the engine) searches the tableView data source for column numbers, requested by the (USER).
2. The applications secondary viewController receives the first column number with a (Notification) sent by the main viewController in viewDidLoad.
3. The applications secondary viewController also identifies the (first column number) as a (Struct Constant) from (MyApplicationConstants_File.swift) in the tableView Delegate.
4. The applications secondary viewController tableView (extension FirstViewController: NSTableViewDelegate) identifies the (first column number Notification) as zero (0).
5. The applications secondary viewController tableView (extension FirstViewController: NSTableViewDelegate) identifies the (Struct Constant first column number).
I have not found literature to illustrate how to make a (variable) visible to the tableView with protocols or delegation, then again, I am not sure, just yet, whether implementing a protocol / delegate class design is the correct path to follow. A literature source with possible suggestions to modify a (variable) to behave like a (Struct Constant) within the tableView delegate would be welcome, and or the comment (not possible).
(Not possible) would allow me to shutdown this avenue of pursuit, gracefully.
Again as always, thank you, and best regards,
jim_k
The secondary viewController code:
The secondary tableView (first column number) code snippet:
} else if tableColumn?.identifier == NSUserInterfaceItemIdentifier(rawValue: "firstColumn") {
/// The (USER) entered the number (10).
/// Identify the (STRUCT CONSTANT) for the (FIRST NUMBER).
/// This (STRUCT CONSTANT) from the constants Swift file is recognized.
let someFirstNumber = TheRequestedNumbersToFind.theFirstNumber
print("First Number Struct Constant Received :: \(someFirstNumber)")
// Prints :
// First Number Struct Constant Received :: 10
// /// Identify the (TRANSFERRED NOTIFICATION NUMBER) for the (FIRST NUMBER).
// /// The (TRANSFERRED NOTIFICATION NUMBER) is (10) but recognized as Zero (0).
// let someFirstNumber = theFirstNumberReceived
// print("THE TRANSFERRED NOTIFICATION NUMBER :: \(someFirstNumber)")
// // Prints :
// // THE TRANSFERRED NOTIFICATION NUMBER :: 0
/// Identify the tableView (theFirstNumberTextField)
let theFirstNumberTextField = Int32(twoNewArrayData[row].first)
/// Test the condition.
if (theFirstNumberTextField) != someFirstNumber {
/// This code identifies the (NOT EQUAL) correctly. <=== No errors.
print("The (someFirstNumber) is (NOT EQUAL) to the (theFirstNumberTextField).")
/// Therefore continue to leave the (theFirstNumberTextField) unchanged.
cellView.textField?.intValue = Int32(twoNewArrayData[row].first)
} else {
/// The application is here because the condition was met,
/// therefore change the (theFirstNumberTextField) font.
/// This code identifies the (EQUAL) correctly.
print("The (someFirstNumber) is (EQUAL) to the (theFirstNumberTextField).")
/// A few numbers (6, 12, 5) are marked incorrectly (Do not know why.)
/// Identify the (theFirstNumberTextField) to change.
cellView.textField?.intValue = Int32(twoNewArrayData[row].first)
/// Change the (TEXT FIELD COLOUR TO BLACK).
cellView.textField?.textColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
/// Change the (TEXTFIELD FONT SIZE) with CGFloat.
/// The (ORIGINAL FONT SIZE) is set to (11).
let fontSize = 14
cellView.textField?.font = NSFont.boldSystemFont(ofSize: CGFloat(fontSize))
} // <=== End of *** if (theFirstNumberTextField) != someFirstNumber ***
} else if tableColumn?.identifier == NSUserInterfaceItemIdentifier(rawValue: "secondColumn") {
// (code continues for other column textFields)
}
return nil
} // <=== End of *** func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? ***