2016-05-13 2 views
0

私はIOSプログラミングでは新しく、BLEペリフェラルをtableViewに保存しようとしています。 私がやった唯一の事はNSArrayの中でそれを格納することです:私のコードがあります:BLEペリフェラルをテーブルビューに保存する目的C

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

あなたなら、私は..私は右ですが、私は私を助けるためにあらゆるexempleを見つけていないことを確認していません私に躊躇しないでください私を助けることができる任意のリンクまたはコードの部分があります。 ありがとうございます==)!

+0

です。その後、周辺機器を使用して自分自身に配列を与えるという複雑さを加えることができます。 – Larme

答えて

0

あなたfoundArray宣言は、私が最初にあなたが(すでに設定されたテキスト付き) `UITableView`を使用する方法についてのチュートリアルを読むことをお勧めしたい

間違った宣言の.h

#import "Emergency.h" 

@interface LiveDataVC : UIViewController 
{ 
    NSMutableArray *foundArray; 
}