osx - NSTableView & NSNotificationCenter strange behavior -



osx - NSTableView & NSNotificationCenter strange behavior -

i got unusual behavior when reloading nstableview info within notification observer.

class mainwindowcontroller: nswindowcontroller, nstableviewdatasource, nstableviewdelegate { var data: string[] = [] @iboutlet var filestableview: nstableview! override func awakefromnib() { super.awakefromnib() nsnotificationcenter.defaultcenter().addobserver(self, selector: "droppedfiles:", name: droppedfilesnotification.notificationname, object: nil) } func droppedfiles(notification: nsnotification!) { info += ["123"] println(data.count) filestableview.reloaddata() } func numberofrowsintableview(tableview: nstableview!) -> int { homecoming data.count } @ibaction func crazytest(anyobject) { nsnotificationcenter.defaultcenter().postnotificationname(droppedfilesnotification.notificationname, object: self, userinfo: [droppedfilesnotification.filenamesparametername: ["123"]]) } }

first phone call of crazytest function displays:

1

seconds phone call of crazytest function displays:

2 3 4

third phone call of crazytest function displays numbers 5-13.

if remove filestableview.reloaddata() droppedfiles function works fine except table view isn't updated. thought why happens , how reload table view there?

edit:

also, there no issue in case calling droppedfiles function straight instead of using nsnotificationcenter. i'd prefer utilize notification center in application.

thanks ahead.

if view-based table view (perhaps implicitly) loads views nibs, awakefromnib method called each time nib loaded. here:

note: calling makeviewwithidentifier:owner: causes awakefromnib called multiple times in app. because makeviewwithidentifier:owner: loads nib passed-in owner, , owner receives awakefromnib call, though it’s awake.

in case, you're registering notification each time. so, you're registering many times on , receive notification 1 time each time registered.

osx cocoa swift nstableview nsnotificationcenter

Comments