【问题标题】:store BLE peripheral in a tableview Objective C将BLE外围设备存储在tableview Objective C中
【发布时间】:2016-05-13 14:35:37
【问题描述】:

我是 IOS 编程新手,我尝试将 BLE 外围设备存储在 tableView 中。 我唯一做的就是将它存储在一个 NSArray 中:这是我的代码:

-(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;
}

我不确定我是否正确,但我没有找到任何可以帮助我的示例。如果您有任何可以帮助我的链接或代码,请不要犹豫。 非常感谢 ==) !

【问题讨论】:

  • 我建议您首先阅读有关如何使用UITableView 的教程(已设置文本)。然后,您可以增加为自己提供外围设备阵列的复杂性。

标签: objective-c tableview bluetooth-lowenergy cbperipheral


【解决方案1】:

你的 foundArray 声明是错误的

声明.h

#import "Emergency.h"

@interface LiveDataVC : UIViewController
{
     NSMutableArray *foundArray;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 2017-02-08
    • 1970-01-01
    • 2017-01-24
    • 2018-04-13
    • 2018-11-18
    • 1970-01-01
    相关资源
    最近更新 更多