This is a “simple” listbox, simple in the fact that is is only one column. but it is 100% contained in a single class, and customizable. It does NOT have multiple sections, but it does have a header (with colors, fonts etc). It supports the standard CellTypes (default, subtitle,value1 and value2)
as of right now (27Mar2023) the code is almost 400 lines (so I won’t post it all here).
It is designed to work with iOS, macOS and tvOS programs from this single code base
NOTE : only iOS has been tested… The others will be over the next few days, and may involve a few changes.
the basic functions and properties are as follows :
//
// Use typeAlias to switch object classes based on platform
//
#if os(macOS)
typealias t1c_tableView = NSTableView
typealias t1c_tableViewCell = NSTableViewCell
typealias t1c_font = NSFont
typealias t1c_color = NSColor
typealias t1c_image = NSImage
typealias t1c_tableViewDelegate = NSTableViewDelegate
typealias t1c_tableViewDataSource = NSTableViewDataSource
typealias t1c_View = NSView
typealias t1c_Label = NSTextField
#else // iOS and tvOS
typealias t1c_tableView = UITableView
typealias t1c_tableViewCell = UITableViewCell
typealias t1c_font = UIFont
typealias t1c_color = UIColor
typealias t1c_image = UIImage
typealias t1c_tableViewDelegate = UITableViewDelegate
typealias t1c_tableViewDataSource = UITableViewDataSource
typealias t1c_View = UIView
typealias t1c_Label = UILabel
#endif
protocol t1c_Protocol : NSObjectProtocol {
func t1c_Clicked(row:Int)
func t1c_DoubleClicked(row:Int)
}
//
// Generic Row Structure
//
public struct t1c_CellData {
var text : String?
var detailText : String?
var accessory : t1c_tableViewCell.AccessoryType = .none
var image : t1c_image? = nil
var rowTag : Int? = nil
}
//
// Main Object Class
//
class oneColumnTable : t1c_tableView, t1c_tableViewDelegate,t1c_tableViewDataSource {
convenience init(frame: CGRect, cellStyle: t1c_tableViewCell.CellStyle = .default) { // must specify style at creation. -initWithFrame: calls this with StylePlain
//
// Heading Functions
//
public final var hasHeading : Bool {
public final var heading : String {
public final var headingFont : t1c_font {
public final var headingHeight : CGFloat {
public final var headingColor : t1c_color {
public final var headingBackColor : t1c_color {
//
// Alternating Row Background Colors
//
public final var oddRowColor : t1c_color {
public final var evenRowColor : t1c_color {
//
// Main Text Attributes
//
public final func text(row:Int,text:String?) {
public final func text(row:Int) -> String? {
public final var textColor : t1c_color {
public final var textFont : t1c_font {
//
// Detail Text Attributes
//
public final func detailText(row:Int,subText:String?) {
public final func detailText(row:Int) -> String? {
public final var detailTextColor : t1c_color {
public final var detailTextFont : t1c_font {
//
// Row Image (is ignored if cellType is value2)
//
public final func image(row:Int,image:t1c_image?)
public final func image(row:Int) -> t1c_image? {
//
// Row Tag
//
public final func rowTag(row:Int,rowTag:Int?) {
public final func rowTag(row:Int) -> Int? {
//
// Row Accessory
//
public final func rowAccessory(row:Int,accessory:t1c_tableViewCell.AccessoryType = .none) {
public final func rowAccessory(row:Int) -> t1c_tableViewCell.AccessoryType {
//
//
// Operational Functions
//
public final func removeAllRows() {
public final func removeRow(row:Int) {
public final func addRow(text:String) {
public final func addRow(cellData:t1c_CellData) {
public final func insertRow(row:Int,text:String) {
public final func insertRow(row:Int,cellData:t1c_CellData) {
public final var listCount : Int {
public final var listIndex : Int {
public final var setRowHeight : CGFloat {
}
EXAMPLE OF USE this produced the above table
let xyz = oneColumnTable(frame:ghost.frame,cellStyle : .subtitle)
the$View.addSubview(xyz)
xyz.clickDelegate = self
for i in(0...10) {
xyz.addRow(text:"text\(i)")
xyz.detailText(row:i,subText: "sub-text")
xyz.rowAccessory(row: i,accessory: .checkmark)
xyz.image(row:i,image: UIImage(named:"pref_FACE"))
}
xyz.listIndex = 4
xyz.textColor = .red
xyz.hasHeading = true
xyz.heading = "Test Heading"