0

I am new in IOS programming and I try to store BLE peripheral in a tableView. The only thing that I did is to store it in an NSArray: there is my code :

-(void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI
{

NSLog (@"Discovered peripheral: %@", [peripheral name]);

NSLog (@"peripheral services before connected: %@, RSSI Value : %@",advertisementData, RSSI);

NSLog(@"adversting data %@",[NSString stringWithFormat:@"%@",[advertisementData description]]);
NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
NSArray *foundArray = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];;

[self.centralManager stopScan];
NSLog(@"Scanning stopped");
NSLog(@"foundArray is %@",foundArray);
self.tblfound = [[UITableView alloc] initWithFrame:CGRectMake(0, 10, 320, 300) style:UITableViewStylePlain];
self.tblfound.dataSource = self;
self.tblfound.delegate = self;
[self.view addSubview:self.tblfound]; 
}
    - (void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals

{
    for (CBPeripheral *peripheral in peripherals) {
        NSLog(@"Retrieved Peripheral %@", peripheral.name);
    }

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  //  static NSString *tableIdentifier = @"BLEDeviceList";
    //CBPeripheral *peripheral = [self.BTLEDevices objectAtIndex:indexPath.row];
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;

    cell.selectionStyle = UITableViewCellSelectionStyleGray;
}


cell.textLabel.text = [foundArray objectAtIndex:indexPath.row];

return cell;
}

I am not sure that I am right but I don't find any exemple to help me .. If you have any link or piece of code which can help me please don't hesitate. Thank you very much ==) !

Maxime
  • 1
  • I'd suggest that first you read a tutorial on how to use a `UITableView` (with already set text). Then after you can add the complexity of feeding yourself the array with peripherals. – Larme May 13 '16 at 14:41

1 Answers1

0

Your foundArray declaration is wrong

Declare .h

#import "Emergency.h"

@interface LiveDataVC : UIViewController
{
     NSMutableArray *foundArray;
}
Gaurav Patel
  • 532
  • 1
  • 5
  • 19