我面临着通过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 *)通知{
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];}
发布于 2016-03-21 05:23:58
多点连接只是为设备提供了一种通信方式-它对通信信息的呈现方式没有任何限制。
您当然可以在表中显示接收到的数据。如果你查看CoachKit,你会发现有一个示例应用程序就是这样做的-它以表格的形式显示从另一台设备接收的消息。
https://stackoverflow.com/questions/36113235
复制相似问题