ios - Class implementing UITableViewDataSource is always null -


i have tableview should have delegate , datasource properties set insertintotableviewdelegate , insertintotableviewdatasource classes respectively. however, insertintotableviewdatasource class returns null.

here code:

class insertintotableviewdatasource: nsobject,uitableviewdatasource {      var data:nsmutablearray      init(with data: nsmutablearray){         self.data = data     }       func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {         return data.count     }      func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {         let cell = tableview.dequeuereusablecellwithidentifier("rowcell", forindexpath: indexpath)         cell.textlabel?.text = data[indexpath.row] as? string         return cell     } } 

here how tableview being set:

override func viewdidload() {     super.viewdidload()     self.title = "testing"     tableview.datasource = insertintotableviewdatasource(with: data)     tableview.delegate = insertintotableviewdelegate() } 

why case?

uitableview not retain datasource, datasource getting deallocated viewdidload function ends.

you need hold reference datasource property in view controller. same thing delegate.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -

r - Update two sets of radiobuttons reactively - shiny -