0

我在通过 MPC 发送数据时遇到困难,设备之间的通信正常工作正在打印在 TextView 上我需要在表格视图中呈现,我可以通过 MPC 从表格视图中添加和删除对象,有人知道吗如果可能,或者这只是 MPC 在 TextView 中的印象。

谢谢你。

我谢谢你。

我将放下发送和接收的代码。

发送数据

-(void) inputIDTransporte {

//testando IDController
IDController * idC = [[IDController alloc] init];


[idC loadIdInput:_textView.text];

//mudando mensagem de saida
[idC.idValues replaceObjectAtIndex:9 withObject:_textField.text];

[idC generateIDOutputByComponentsScheme];

NSLog(@"idValues:%@", idC.idValues);
NSLog(@"idOutput:%@", idC.idOutput);

NSLog(@"index9: %@",idC.idValues[9]);

NSString* str= [idC.idValues objectAtIndex:9];
NSData* dataToSend=[str dataUsingEncoding:NSUTF8StringEncoding];

NSArray *allPeers = _appDelegate.mcManager.session.connectedPeers;
NSError *error;

[_appDelegate.mcManager.session sendData:dataToSend
                                 toPeers:allPeers
                                withMode:MCSessionSendDataReliable
                                   error:&error];
[idC.componentsScheme setValue:str forKey:@"name"];
[self.tableView reloadData];

if (error) {
    NSLog(@"%@", [error localizedDescription]);
}

}

接收数据

-(void)didReceiveDataWithNotification:(NSNotification *)notification{

MCPeerID *peerID = [[notification userInfo] objectForKey:@"peerID"];
NSString *peerDisplayName = peerID.displayName;

NSData *receivedData = [[notification userInfo] objectForKey:@"data"];
NSString *receivedText = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];

[_tvChat performSelectorOnMainThread:@selector(setText:) withObject:[_tvChat.text stringByAppendingString:[NSString stringWithFormat:@"%@\n", receivedText]] waitUntilDone:NO];
[_tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

}

4

1 回答 1

0

多点连接只是为设备提供了一种通信方式——它对通信信息的呈现方式没有任何限制。

您当然可以在表格中显示接收到的数据。如果您查看CoachKit,您会看到有一个示例应用程序正是这样做的 - 它在表格中显示从另一个设备接收到的消息。

于 2016-03-20T21:23:58.413 回答