【问题标题】:Display available Bluetooth list in UITableView在 UITableView 中显示可用的蓝牙列表
【发布时间】:2013-03-10 12:02:19
【问题描述】:

我是游戏开发的新手。我正在创建一个通过蓝牙连接的多人游戏。现在,在我的项目中,我正在使用 Game Kit 框架来检测可用的蓝牙设备。此可用蓝牙列表显示在GKPeerPicker 控制器中。但现在我想在UITableView 中显示可用的蓝牙列表。

【问题讨论】:

    标签: ios ios5 bluetooth gamekit core-bluetooth


    【解决方案1】:
    -(void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals{
        NSLog(@"This is it!");
    // store the list of devices in the NSArray and then go to table view delegates.
    
    
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [peripherals count];
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
        }
    
    
        cell.textLabel.text = [peripherals objectAtIndex:indexPath.row];
    
    
    
        return cell;
    }
    

    【讨论】:

    • 我仍然没有在 uitableview 中获得可用的蓝牙列表
    • 外设 = [NSArray arrayWithObjects:nil, nil]; options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] [cbmanager scanForPeripheralsWithServices:peripherals options:options];
    • 你的数组是 nil 那么它如何加载并且你能看到表格
    • - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [外设数]; }
    • 我也使用这个 委托和所有这些方法
    【解决方案2】:

    这是显示可用的蓝牙设备列表的最佳示例代码,他解释得很清楚
    Displaying bluetooth devices list

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 2012-04-28
      • 2012-09-06
      相关资源
      最近更新 更多