I have a tableview which loads peripherals received from BLE. ThisNSMutableArray
is maintained in the appDelegate. Whenever a new peripheral is received in the app I add it to the array.
My problem is that everything works fine on first run and the table updates accordingly and I use the app for a while. Then I reset(CoreData, UserDefaults in app) my app and go back to the initial screen.
I use the following code to get back to initial screen of my app
class func showStartScreen() {
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let nav = storyboard.instantiateInitialViewController()
(UIApplication.sharedApplication().delegate)!.window!!.rootViewController = nav
(UIApplication.sharedApplication().delegate)!.window!!.makeKeyAndVisible()
}
When I reset app data and come back to the screen where I display the peripherals in the tableview, it doesn't updat. I can see that the peripherals are added in the array but when I reload the tableview tableview:cellForRowAtIndexPath
is not called.
I tried to add a single dummy cell into the table and at that point tableview:cellForRowAtIndexPath
is called properly but only for the dummy cell.
numberOfRowsInSection
returns the correct value and my datasource and delegate are correctly set too.
I clear the list every time a scan is started for BLE peripherals
In AppDelegate:
func discoveredPeripheral(peripheral: CAPeripheral) {
print("added peripheral")
var isDuplicate:Bool = false
for object in scannedPeripherals! {
if object is CAPeripheral {
let newPeripheral = object as! CAPeripheral
// Need to add check of nil
if newPeripheral.peripheral_UUID == peripheral.peripheral_UUID {
isDuplicate = true
}
}
}
if (!isDuplicate) {
self.scannedPeripherals?.addObject(peripheral)
}
}
In ScanVC:
func discoveredPeripheral(peripheral: CAPeripheral) {
dispatch_async(dispatch_get_main_queue()) {
self.peripheralTableView.reloadData()
}
}
Hope I have explained well. Why is tableview:cellForRowAtIndexPath
not called when I clearly have data to display?