【问题标题】:Receive data via MPC in a TableView - Objective C在 TableView 中通过 MPC 接收数据 - Objective C
【发布时间】:2016-07-06 21:51:46
【问题描述】:

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

}

【问题讨论】:

    标签: ios objective-c cocoa-touch multipeer-connectivity mpc


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-12
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多