2017-06-12 3 views
1

J'ai un problème très étrange où les cellules lors du ré-rendu de NSTableView semblent obtenir une coloration aléatoire et afficher du texte. Ceci est MacOS pas l'iPhone. J'utilise un dictionnaire dans les données de variable pour afficher les résultats dans la tableNSTableView Table Voir la mémoire de la cellule Problème

Il est plus facile de montrer comment il devrait ressembler à ceci ... enter image description here

Quand je lance à nouveau la simulation et supprimer toutes les colonnes de la table et les recréer pour correspondre à une « année » au lieu de mois , alors ça ressemble à ça. enter image description here

C'est une erreur très étrange. Je ne suis pas sûr de ce que je fais de mal qui pourrait causer cela, mais je soupçonne un problème de mémoire avec quelque chose que je fais.

Voici mon code pour le contrôleur.

import Cocoa 

class ViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource { 

    //@JA - Simulation Settings Tab 
    @IBOutlet weak var theTableview: NSTableView! 
    @IBOutlet weak var reportTypePopUpButton: NSPopUpButton! 
    @IBOutlet weak var businessPopUpButton: NSPopUpButton! 
    @IBOutlet weak var numberOfDaysToSimulateTextField: NSTextField! 
    @IBOutlet weak var startDateTextField: NSTextField! 
    @IBOutlet weak var startingBudgetTextField: NSTextField! 

    //Default Multidimensional Dictionary 
    var data = [ 
     [ 
      "name":"Click Start to Begin", 
      "columninfo" :["0"] 
     ] 
    ] 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     //First remove all columns 
     let columns = self.theTableview.tableColumns 
     columns.forEach { 
      self.theTableview.removeTableColumn($0) 
     } 

     //@JA - This fixes the last column not being shown correctly 
     self.theTableview?.columnAutoresizingStyle = .noColumnAutoresizing 

     for index in 0...1 { 
      let column = NSTableColumn(identifier: "defaultheader") 
      if(index != 0){ 
       column.title = "Month \(index)" 
      }else{ 
       column.title = "Factors" 
      } 

      self.theTableview.addTableColumn(column) 
     } 


     let date = NSDate() 
     let dateFormatter = DateFormatter() 
     dateFormatter.dateFormat = "yyyy-MM-dd" 
     let dateString = dateFormatter.string(from:date as Date) 

     startDateTextField.stringValue = dateString 

     // Do any additional setup after loading the view. 

     self.theTableview.reloadData() 
    } 

    override var representedObject: Any? { 
     didSet { 
     // Update the view, if already loaded. 
     } 
    } 

    //@JA - Tableview Delegate & Datasource Functions 
    func numberOfRows(in tableView: NSTableView) -> Int { 
     return data.count 
    } 

    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { 

     let currentColumnIndex = tableView.tableColumns.index(of: tableColumn!) 

     if let cell = tableView.make(withIdentifier: "defaultcell", owner: nil) as? NSTableCellView { 
     //if let cell = tableView.reuse { 
      if tableColumn == tableView.tableColumns[0]{ //@JA - If this is the first column then show the row names corespondingly 
       cell.textField?.stringValue = data[row]["name"] as! String 
      }else{ 
       let columnInfo = data[row]["columninfo"] as! [String] 

       let isIndexValid = columnInfo.indices.contains(currentColumnIndex!-1) 
       if(isIndexValid){ 
        cell.textField?.stringValue = columnInfo[currentColumnIndex!-1] 
       } 
      } 

      //Highlight Rows with rule to do so 
      if data[row]["highlightrow"] != nil{ 
       let bghighlight = data[row]["highlightrow"] as! [String:NSNumber] 
       cell.textField?.backgroundColor = NSColor.init(red: CGFloat(bghighlight["red"]!), green: CGFloat(bghighlight["green"]!), blue: CGFloat(bghighlight["blue"]!), alpha: CGFloat(bghighlight["alpha"]!)) 
       cell.textField?.textColor = NSColor.init(red: CGFloat(bghighlight["tred"]!), green: CGFloat(bghighlight["tgreen"]!), blue: CGFloat(bghighlight["tblue"]!), alpha: CGFloat(bghighlight["talpha"]!)) 
      } 

      //Marked rows will show ----- for content to fill it out 
      if data[row]["mark"] != nil{ 
       if data[row]["mark"] as! Bool == true && currentColumnIndex != 0{ 
        cell.textField?.stringValue = "---------------" 
       } 
      } 

      return cell 
     } 
     return nil 
    } 

    //@JA - Helper Functions 
    func calculateTableHeaders(){ 

     //First remove all columns 
     let columns = self.theTableview.tableColumns 
     columns.forEach { 
      self.theTableview.removeTableColumn($0) 
     } 

     //Find out how many days we want to simulate 
     let numOfDays = Int(numberOfDaysToSimulateTextField.intValue) 
     let columnType = reportTypePopUpButton.titleOfSelectedItem 

     //Generic Setting for Date 
     let dateFormatter = DateFormatter() 
     dateFormatter.dateFormat = "yyyy-MM-dd" 

     let startDate = dateFormatter.date(from:startDateTextField.stringValue) 
     var components = DateComponents() 

     var numOfColumns = 150 //Default Column Setting. Always overwritten 

     print("columnType=\(columnType!)") 

     if(columnType == "Daily"){ 
      numOfColumns = Int(numOfDays) 
      components = DateComponents() //to reset it 
     } 
     if(columnType == "Monthly"){ 
      components.setValue(numOfDays, for: .day) 
      let futureDate = Calendar.current.date(byAdding: components, to: startDate!) 
      numOfColumns = futureDate!.interval(ofComponent: .month, fromDate: startDate!) //The number of months needed column wise 
     } 
     if(columnType == "Yearly"){ 
      components.setValue(numOfDays, for: .day) 
      let futureDate = Calendar.current.date(byAdding: components, to: startDate!) 
      numOfColumns = futureDate!.interval(ofComponent: .year, fromDate: startDate!) //The number of months needed column wise 
     } 

     dateFormatter.dateFormat = "dd MMM yyyy" //this is format we want to use for column names 
     for index in 0...numOfColumns { 
      let column = NSTableColumn(identifier: "defaultheader") 
      if(index != 0){ 
       components = DateComponents() //reset it 
       if(columnType == "Daily"){ 
        components.setValue(index, for: .day) 
       }else if(columnType == "Monthly"){ 
        components.setValue(index, for: .month) 
       }else if(columnType == "Yearly"){ 
        components.setValue(index, for: .year) 
       } 
       let dayDate = Calendar.current.date(byAdding: components, to: startDate!) 
       column.title = dateFormatter.string(from:dayDate!) 
      }else{ 
       column.title = "Factors" 
       column.width = 200 
      } 

      self.theTableview.addTableColumn(column) 
     } 

    } 

    @IBAction func startsimulation(_ sender: NSButton) { 
     calculateTableHeaders() 
     let budget = startingBudgetTextField.doubleValue 
     let businessname = businessPopUpButton.titleOfSelectedItem! 

     var biz:Business? 

     if (businessname == "PoolService123.com"){ 
      biz = PoolService123(bizname: businessname, startbudget:Decimal(budget)) 
     } 

     let sim = Simulator(biz: biz!) 

     data = [] 
     data = sim.run() as! [Dictionary<String, Any>] 


     theTableview.reloadData() 
    } 

} 

extension Date { 

    func interval(ofComponent comp: Calendar.Component, fromDate date: Date) -> Int { 

     let currentCalendar = Calendar.current 

     guard let start = currentCalendar.ordinality(of: comp, in: .era, for: date) else { return 0 } 
     guard let end = currentCalendar.ordinality(of: comp, in: .era, for: self) else { return 0 } 

     return end - start 
    } 
} 

cours pertinents sa fonction de notre définis comme ceci:

Simulator.swift

import Foundation 


class Simulator { 

    var business: Business 
    var daysToSimulate = 365 

    //Must be initialized with a business 
    init(biz: Business) { 
     self.business = biz 
    } 

    public func run() -> Any{ 
     let data = self.business.data! //Grabs the default data structure from which to fill in details 

     return data 
    } 
} 

Business.swift

import Foundation 

class Business { 
    public var name: String = "" 
    public var budget:Decimal = 0.0 
    public var data: [Dictionary<String, Any>]? 
    public var money:Decimal = 0.0 //This represents its current financial state 

    init(bizname: String,startbudget: Decimal){ 
     self.name = bizname 
     self.budget = startbudget 
     self.money = startbudget 
    } 
} 

PoolService123.swift

import Foundation 

class PoolService123 : Business{ 
    override init(bizname: String, startbudget: Decimal) { 
     //@JA - Call super to do generic business stuff that is the same 
     super.init(bizname: bizname, startbudget: startbudget) 

     self.data = [ 
      [ 
       "name":"Starting Budget", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Regions Targeting", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Marketing & Customers", 
       "columninfo" :["-"], 
       "highlightrow":["red":0.0,"green":0.0,"blue":0.0,"alpha":1.0,"tred":1.0,"tgreen":1.0,"tblue":1.0,"talpha":1.0], 
       "mark":true 
      ], 
      [ 
       "name":"Adwords Clicks", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Adwords Conversions", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Adwords Customers Acquired", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Customers Gained", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Customers Lost", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Total Customers", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Expenses", 
       "columninfo" :["-"], 
       "highlightrow":["red":0.2,"green":0.0,"blue":0.0,"alpha":1.0,"tred":1.0,"tgreen":1.0,"tblue":1.0,"talpha":1.0], 
       "mark":true 
      ], 
      [ 
       "name":"Adwords Cost", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Total Expenses", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Revenue", 
       "columninfo" :["-"], 
       "highlightrow":["red":0.0,"green":0.2,"blue":0.0,"alpha":1.0,"tred":1.0,"tgreen":1.0,"tblue":1.0,"talpha":1.0], 
       "mark":true 
      ], 
      [ 
       "name":"Gross Income", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Net Income", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Net Worth", 
       "columninfo" :["0"] 
      ], 
      [ 
       "name":"Business Partner Income", 
       "columninfo" :["0"] 
      ] 
     ] 
    } 
} 

choses que j'ai essayé:

Quand je re-Simuler et garder le mois, il semble être correct et rien ne se passe mal, cela semble se produire que lorsque je passer à le faire par années, ce qui fait moins de colonnes dans l'ensemble.

En outre, si je continue à cliquer sur la simulation pendant les années, cela devient de pire en pire. Cela ressemble en fin de compte ... enter image description here

Si je commence chaque année et continue à faire la simulation, cela fonctionne très bien. Passer à mensuel et ça marche bien! Revenez à l'année après avoir fait cela et ... ça rebute à nouveau. Il est clair que quelque chose que je fais quand je viens de la simulation annuelle à la simulation mensuelle cause un problème.

Autre chose que j'ai remarqué est l'erreur des couleurs et les données de texte est toujours dans la même position lorsque je fais le test. J'ai fait un point de rupture sur le dictionnaire de données à chaque point et je n'y vois aucune corruption.

Certains Debug intéressants Résultats

J'ajouté cette ligne à cette fonction func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {

print("currentColumnIndex=\(currentColumnIndex ?? -1) , row=\(row)") 

je reçois la sortie de débogage suivante quand je fais l'année qui est très étrange, en quelque sorte son rendre les colonnes dans l'ordre puis séquentiellement à nouveau?

columnType=Yearly 
currentColumnIndex=0 , row=0 
currentColumnIndex=0 , row=1 
currentColumnIndex=0 , row=2 
currentColumnIndex=0 , row=3 
currentColumnIndex=0 , row=4 
currentColumnIndex=0 , row=5 
currentColumnIndex=0 , row=6 
currentColumnIndex=0 , row=7 
currentColumnIndex=0 , row=8 
currentColumnIndex=0 , row=9 
currentColumnIndex=0 , row=10 
currentColumnIndex=0 , row=11 
currentColumnIndex=0 , row=12 
currentColumnIndex=0 , row=13 
currentColumnIndex=0 , row=14 
currentColumnIndex=0 , row=15 
currentColumnIndex=0 , row=16 
currentColumnIndex=1 , row=0 
currentColumnIndex=1 , row=1 
currentColumnIndex=1 , row=2 
currentColumnIndex=1 , row=3 
currentColumnIndex=1 , row=4 
currentColumnIndex=1 , row=5 
currentColumnIndex=1 , row=6 
currentColumnIndex=1 , row=7 
currentColumnIndex=1 , row=8 
currentColumnIndex=1 , row=9 
currentColumnIndex=1 , row=10 
currentColumnIndex=1 , row=11 
currentColumnIndex=1 , row=12 
currentColumnIndex=1 , row=13 
currentColumnIndex=1 , row=14 
currentColumnIndex=1 , row=15 
currentColumnIndex=1 , row=16 
currentColumnIndex=2 , row=0 
currentColumnIndex=2 , row=1 
currentColumnIndex=2 , row=2 
currentColumnIndex=2 , row=3 
currentColumnIndex=2 , row=4 
currentColumnIndex=2 , row=5 
currentColumnIndex=2 , row=6 
currentColumnIndex=2 , row=7 
currentColumnIndex=2 , row=8 
currentColumnIndex=2 , row=9 
currentColumnIndex=2 , row=10 
currentColumnIndex=2 , row=11 
currentColumnIndex=2 , row=12 
currentColumnIndex=2 , row=13 
currentColumnIndex=2 , row=14 
currentColumnIndex=2 , row=15 
currentColumnIndex=2 , row=16 
currentColumnIndex=3 , row=0 
currentColumnIndex=3 , row=1 
currentColumnIndex=3 , row=2 
currentColumnIndex=3 , row=3 
currentColumnIndex=3 , row=4 
currentColumnIndex=3 , row=5 
currentColumnIndex=3 , row=6 
currentColumnIndex=3 , row=7 
currentColumnIndex=3 , row=8 
currentColumnIndex=3 , row=9 
currentColumnIndex=3 , row=10 
currentColumnIndex=3 , row=11 
currentColumnIndex=3 , row=12 
currentColumnIndex=3 , row=13 
currentColumnIndex=3 , row=14 
currentColumnIndex=3 , row=15 
currentColumnIndex=3 , row=16 
currentColumnIndex=4 , row=0 
currentColumnIndex=4 , row=1 
currentColumnIndex=4 , row=2 
currentColumnIndex=4 , row=3 
currentColumnIndex=4 , row=4 
currentColumnIndex=4 , row=5 
currentColumnIndex=4 , row=6 
currentColumnIndex=4 , row=7 
currentColumnIndex=4 , row=8 
currentColumnIndex=4 , row=9 
currentColumnIndex=4 , row=10 
currentColumnIndex=4 , row=11 
currentColumnIndex=4 , row=12 
currentColumnIndex=4 , row=13 
currentColumnIndex=4 , row=14 
currentColumnIndex=4 , row=15 
currentColumnIndex=4 , row=16 
currentColumnIndex=5 , row=0 
currentColumnIndex=5 , row=1 
currentColumnIndex=5 , row=2 
currentColumnIndex=5 , row=3 
currentColumnIndex=5 , row=4 
currentColumnIndex=5 , row=5 
currentColumnIndex=5 , row=6 
currentColumnIndex=5 , row=7 
currentColumnIndex=5 , row=8 
currentColumnIndex=5 , row=9 
currentColumnIndex=5 , row=10 
currentColumnIndex=5 , row=11 
currentColumnIndex=5 , row=12 
currentColumnIndex=5 , row=13 
currentColumnIndex=5 , row=14 
currentColumnIndex=5 , row=15 
currentColumnIndex=5 , row=16 
currentColumnIndex=6 , row=0 
currentColumnIndex=6 , row=1 
currentColumnIndex=6 , row=2 
currentColumnIndex=6 , row=3 
currentColumnIndex=6 , row=4 
currentColumnIndex=6 , row=5 
currentColumnIndex=6 , row=6 
currentColumnIndex=6 , row=7 
currentColumnIndex=6 , row=8 
currentColumnIndex=6 , row=9 
currentColumnIndex=6 , row=10 
currentColumnIndex=6 , row=11 
currentColumnIndex=6 , row=12 
currentColumnIndex=6 , row=13 
currentColumnIndex=6 , row=14 
currentColumnIndex=6 , row=15 
currentColumnIndex=6 , row=16 
currentColumnIndex=7 , row=0 
currentColumnIndex=7 , row=1 
currentColumnIndex=7 , row=2 
currentColumnIndex=7 , row=3 
currentColumnIndex=7 , row=4 
currentColumnIndex=7 , row=5 
currentColumnIndex=7 , row=6 
currentColumnIndex=7 , row=7 
currentColumnIndex=7 , row=8 
currentColumnIndex=7 , row=9 
currentColumnIndex=7 , row=10 
currentColumnIndex=7 , row=11 
currentColumnIndex=7 , row=12 
currentColumnIndex=7 , row=13 
currentColumnIndex=7 , row=14 
currentColumnIndex=7 , row=15 
currentColumnIndex=7 , row=16 
currentColumnIndex=8 , row=0 
currentColumnIndex=8 , row=1 
currentColumnIndex=8 , row=2 
currentColumnIndex=8 , row=3 
currentColumnIndex=8 , row=4 
currentColumnIndex=8 , row=5 
currentColumnIndex=8 , row=6 
currentColumnIndex=8 , row=7 
currentColumnIndex=8 , row=8 
currentColumnIndex=8 , row=9 
currentColumnIndex=8 , row=10 
currentColumnIndex=8 , row=11 
currentColumnIndex=8 , row=12 
currentColumnIndex=8 , row=13 
currentColumnIndex=8 , row=14 
currentColumnIndex=8 , row=15 
currentColumnIndex=8 , row=16 
currentColumnIndex=9 , row=0 
currentColumnIndex=9 , row=1 
currentColumnIndex=9 , row=2 
currentColumnIndex=9 , row=3 
currentColumnIndex=9 , row=4 
currentColumnIndex=9 , row=5 
currentColumnIndex=9 , row=6 
currentColumnIndex=9 , row=7 
currentColumnIndex=9 , row=8 
currentColumnIndex=9 , row=9 
currentColumnIndex=9 , row=10 
currentColumnIndex=9 , row=11 
currentColumnIndex=9 , row=12 
currentColumnIndex=9 , row=13 
currentColumnIndex=9 , row=14 
currentColumnIndex=9 , row=15 
currentColumnIndex=9 , row=16 
currentColumnIndex=10 , row=0 
currentColumnIndex=10 , row=1 
currentColumnIndex=10 , row=2 
currentColumnIndex=10 , row=3 
currentColumnIndex=10 , row=4 
currentColumnIndex=10 , row=5 
currentColumnIndex=10 , row=6 
currentColumnIndex=10 , row=7 
currentColumnIndex=10 , row=8 
currentColumnIndex=10 , row=9 
currentColumnIndex=10 , row=10 
currentColumnIndex=10 , row=11 
currentColumnIndex=10 , row=12 
currentColumnIndex=10 , row=13 
currentColumnIndex=10 , row=14 
currentColumnIndex=10 , row=15 
currentColumnIndex=10 , row=16 
currentColumnIndex=0 , row=0 
currentColumnIndex=1 , row=0 
currentColumnIndex=2 , row=0 
currentColumnIndex=3 , row=0 
currentColumnIndex=4 , row=0 
currentColumnIndex=5 , row=0 
currentColumnIndex=6 , row=0 
currentColumnIndex=7 , row=0 
currentColumnIndex=8 , row=0 
currentColumnIndex=9 , row=0 
currentColumnIndex=10 , row=0 
currentColumnIndex=0 , row=1 
currentColumnIndex=1 , row=1 
currentColumnIndex=2 , row=1 
currentColumnIndex=3 , row=1 
currentColumnIndex=4 , row=1 
currentColumnIndex=5 , row=1 
currentColumnIndex=6 , row=1 
currentColumnIndex=7 , row=1 
currentColumnIndex=8 , row=1 
currentColumnIndex=9 , row=1 
currentColumnIndex=10 , row=1 
currentColumnIndex=0 , row=2 
currentColumnIndex=1 , row=2 
currentColumnIndex=2 , row=2 
currentColumnIndex=3 , row=2 
currentColumnIndex=4 , row=2 
currentColumnIndex=5 , row=2 
currentColumnIndex=6 , row=2 
currentColumnIndex=7 , row=2 
currentColumnIndex=8 , row=2 
currentColumnIndex=9 , row=2 
currentColumnIndex=10 , row=2 
currentColumnIndex=0 , row=3 
currentColumnIndex=1 , row=3 
currentColumnIndex=2 , row=3 
currentColumnIndex=3 , row=3 
currentColumnIndex=4 , row=3 
currentColumnIndex=5 , row=3 
currentColumnIndex=6 , row=3 
currentColumnIndex=7 , row=3 
currentColumnIndex=8 , row=3 
currentColumnIndex=9 , row=3 
currentColumnIndex=10 , row=3 
currentColumnIndex=0 , row=4 
currentColumnIndex=1 , row=4 
currentColumnIndex=2 , row=4 
currentColumnIndex=3 , row=4 
currentColumnIndex=4 , row=4 
currentColumnIndex=5 , row=4 
currentColumnIndex=6 , row=4 
currentColumnIndex=7 , row=4 
currentColumnIndex=8 , row=4 
currentColumnIndex=9 , row=4 
currentColumnIndex=10 , row=4 
currentColumnIndex=0 , row=5 
currentColumnIndex=1 , row=5 
currentColumnIndex=2 , row=5 
currentColumnIndex=3 , row=5 
currentColumnIndex=4 , row=5 
currentColumnIndex=5 , row=5 
currentColumnIndex=6 , row=5 
currentColumnIndex=7 , row=5 
currentColumnIndex=8 , row=5 
currentColumnIndex=9 , row=5 
currentColumnIndex=10 , row=5 
currentColumnIndex=0 , row=6 
currentColumnIndex=1 , row=6 
currentColumnIndex=2 , row=6 
currentColumnIndex=3 , row=6 
currentColumnIndex=4 , row=6 
currentColumnIndex=5 , row=6 
currentColumnIndex=6 , row=6 
currentColumnIndex=7 , row=6 
currentColumnIndex=8 , row=6 
currentColumnIndex=9 , row=6 
currentColumnIndex=10 , row=6 
currentColumnIndex=0 , row=7 
currentColumnIndex=1 , row=7 
currentColumnIndex=2 , row=7 
currentColumnIndex=3 , row=7 
currentColumnIndex=4 , row=7 
currentColumnIndex=5 , row=7 
currentColumnIndex=6 , row=7 
currentColumnIndex=7 , row=7 
currentColumnIndex=8 , row=7 
currentColumnIndex=9 , row=7 
currentColumnIndex=10 , row=7 
currentColumnIndex=0 , row=8 
currentColumnIndex=1 , row=8 
currentColumnIndex=2 , row=8 
currentColumnIndex=3 , row=8 
currentColumnIndex=4 , row=8 
currentColumnIndex=5 , row=8 
currentColumnIndex=6 , row=8 
currentColumnIndex=7 , row=8 
currentColumnIndex=8 , row=8 
currentColumnIndex=9 , row=8 
currentColumnIndex=10 , row=8 
currentColumnIndex=0 , row=9 
currentColumnIndex=1 , row=9 
currentColumnIndex=2 , row=9 
currentColumnIndex=3 , row=9 
currentColumnIndex=4 , row=9 
currentColumnIndex=5 , row=9 
currentColumnIndex=6 , row=9 
currentColumnIndex=7 , row=9 
currentColumnIndex=8 , row=9 
currentColumnIndex=9 , row=9 
currentColumnIndex=10 , row=9 
currentColumnIndex=0 , row=10 
currentColumnIndex=1 , row=10 
currentColumnIndex=2 , row=10 
currentColumnIndex=3 , row=10 
currentColumnIndex=4 , row=10 
currentColumnIndex=5 , row=10 
currentColumnIndex=6 , row=10 
currentColumnIndex=7 , row=10 
currentColumnIndex=8 , row=10 
currentColumnIndex=9 , row=10 
currentColumnIndex=10 , row=10 
currentColumnIndex=0 , row=11 
currentColumnIndex=1 , row=11 
currentColumnIndex=2 , row=11 
currentColumnIndex=3 , row=11 
currentColumnIndex=4 , row=11 
currentColumnIndex=5 , row=11 
currentColumnIndex=6 , row=11 
currentColumnIndex=7 , row=11 
currentColumnIndex=8 , row=11 
currentColumnIndex=9 , row=11 
currentColumnIndex=10 , row=11 
currentColumnIndex=0 , row=12 
currentColumnIndex=1 , row=12 
currentColumnIndex=2 , row=12 
currentColumnIndex=3 , row=12 
currentColumnIndex=4 , row=12 
currentColumnIndex=5 , row=12 
currentColumnIndex=6 , row=12 
currentColumnIndex=7 , row=12 
currentColumnIndex=8 , row=12 
currentColumnIndex=9 , row=12 
currentColumnIndex=10 , row=12 
currentColumnIndex=0 , row=13 
currentColumnIndex=1 , row=13 
currentColumnIndex=2 , row=13 
currentColumnIndex=3 , row=13 
currentColumnIndex=4 , row=13 
currentColumnIndex=5 , row=13 
currentColumnIndex=6 , row=13 
currentColumnIndex=7 , row=13 
currentColumnIndex=8 , row=13 
currentColumnIndex=9 , row=13 
currentColumnIndex=10 , row=13 
currentColumnIndex=0 , row=14 
currentColumnIndex=1 , row=14 
currentColumnIndex=2 , row=14 
currentColumnIndex=3 , row=14 
currentColumnIndex=4 , row=14 
currentColumnIndex=5 , row=14 
currentColumnIndex=6 , row=14 
currentColumnIndex=7 , row=14 
currentColumnIndex=8 , row=14 
currentColumnIndex=9 , row=14 
currentColumnIndex=10 , row=14 
currentColumnIndex=0 , row=15 
currentColumnIndex=1 , row=15 
currentColumnIndex=2 , row=15 
currentColumnIndex=3 , row=15 
currentColumnIndex=4 , row=15 
currentColumnIndex=5 , row=15 
currentColumnIndex=6 , row=15 
currentColumnIndex=7 , row=15 
currentColumnIndex=8 , row=15 
currentColumnIndex=9 , row=15 
currentColumnIndex=10 , row=15 
currentColumnIndex=0 , row=16 
currentColumnIndex=1 , row=16 
currentColumnIndex=2 , row=16 
currentColumnIndex=3 , row=16 
currentColumnIndex=4 , row=16 
currentColumnIndex=5 , row=16 
currentColumnIndex=6 , row=16 
currentColumnIndex=7 , row=16 
currentColumnIndex=8 , row=16 
currentColumnIndex=9 , row=16 
currentColumnIndex=10 , row=16 

Ce qui est intéressant ce résultat est lors du rendu mensuel par défaut rendu je le fais semble rendre le tableView dans un ordre différent?

columnType=Monthly 
currentColumnIndex=0 , row=0 
currentColumnIndex=1 , row=0 
currentColumnIndex=2 , row=0 
currentColumnIndex=3 , row=0 
currentColumnIndex=4 , row=0 
currentColumnIndex=5 , row=0 
currentColumnIndex=6 , row=0 
currentColumnIndex=7 , row=0 
currentColumnIndex=8 , row=0 
currentColumnIndex=9 , row=0 
currentColumnIndex=10 , row=0 
currentColumnIndex=11 , row=0 
currentColumnIndex=12 , row=0 
... 

currentColumnIndex=0 , row=0 
currentColumnIndex=1 , row=0 
currentColumnIndex=2 , row=0 
currentColumnIndex=3 , row=0 
currentColumnIndex=4 , row=0 
currentColumnIndex=5 , row=0 
currentColumnIndex=6 , row=0 
currentColumnIndex=7 , row=0 
currentColumnIndex=8 , row=0 
currentColumnIndex=9 , row=0 
currentColumnIndex=10 , row=0 
currentColumnIndex=11 , row=0 
currentColumnIndex=12 , row=0 
... 
currentColumnIndex=0 , row=1 
currentColumnIndex=1 , row=1 
currentColumnIndex=2 , row=1 
currentColumnIndex=3 , row=1 
currentColumnIndex=4 , row=1 
currentColumnIndex=5 , row=1 
currentColumnIndex=6 , row=1 
currentColumnIndex=7 , row=1 
currentColumnIndex=8 , row=1 
currentColumnIndex=9 , row=1 
currentColumnIndex=10 , row=1 
currentColumnIndex=11 , row=1 
currentColumnIndex=12 , row=1 
.... 
currentColumnIndex=0 , row=2 
currentColumnIndex=1 , row=2 
currentColumnIndex=2 , row=2 
currentColumnIndex=3 , row=2 
currentColumnIndex=4 , row=2 
currentColumnIndex=5 , row=2 
currentColumnIndex=6 , row=2 
currentColumnIndex=7 , row=2 
currentColumnIndex=8 , row=2 
currentColumnIndex=9 , row=2 
currentColumnIndex=10 , row=2 
currentColumnIndex=11 , row=2 
currentColumnIndex=12 , row=2 

... currentColumnIndex = 120, rang = 16

Je n'ai pas eu assez de caractères pour montrer modèle complet, mais récapitulé ici.

Effacer les résultats de la table semble seulement aider temporairement, je le fais en réglant data = [] et en rechargeant la table.

Répondre

3

Tout d'abord, ce n'est pas un problème de mémoire.

Les cellules de vue de table sont réutilisées, vous devez vous assurer que tous les éléments de l'interface utilisateur sont définis dans un état défini.

Le code contient une clause if, donc vous devez ajouter un équilibre entre else clause pour définir les couleurs aux valeurs par défaut, par exemple:

if let bghighlight = data[row]["highlightrow"] as? [String:NSNumber] { 
     cell.textField?.backgroundColor = NSColor(red: CGFloat(bghighlight["red"]!), green: CGFloat(bghighlight["green"]!), blue: CGFloat(bghighlight["blue"]!), alpha: CGFloat(bghighlight["alpha"]!)) 
     cell.textField?.textColor = NSColor(red: CGFloat(bghighlight["tred"]!), green: CGFloat(bghighlight["tgreen"]!), blue: CGFloat(bghighlight["tblue"]!), alpha: CGFloat(bghighlight["talpha"]!)) 
    } else { 
     cell.textField?.backgroundColor = .white 
     cell.textField?.textColor = .textColor 
    } 

J'ai changé un peu le code à utiliser les liaisons en option, qui est plus efficace. PS: Je recommande de mapper le JSON à un modèle de données, créer les mêmes couleurs encore et encore est inutilement cher.

+0

en essayant cela maintenant une seconde –

+0

L'autre sur la marque que j'ai dû enlever, mais il semble fonctionner pour résoudre le problème de couleur. Les autres cellules du tableau où la valeur est nulle à cause des données semblent toujours étranges mais il semble l'avoir corrigé. Je vais mettre à jour à quoi cela ressemble dans ces cas-là. Merci pour cela. –

+0

Avez-vous des exemples pour mapper le JSON à un modèle de données? Je suis encore un peu nouveau sur la façon dont les tables fonctionnent sur les MacOS –