我在通过 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];
}