我正在使用自定义视图来显示我的回合制游戏中的匹配列表。使用自定义视图时,我在显示设备离线时玩家参与的当前游戏列表时遇到问题。但是当我检查游戏中心默认视图时,即使离线,比赛也能正常显示。我用来填充数组的代码如下(摘自 Ray Wenderlich 的书中)
[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error)
{
if (error)
{
NSLog(@"%@", error.localizedDescription);
}
else
{
NSMutableArray *myMatches = [NSMutableArray array];
NSMutableArray *otherMatches = [NSMutableArray array];
NSMutableArray *endedMatches = [NSMutableArray array];
for (GKTurnBasedMatch *m in matches)
{
GKTurnBasedMatchOutcome myOutcome;
for (GKTurnBasedParticipant *par in m.participants)
{
if ([par.playerID isEqualToString: [GKLocalPlayer localPlayer].playerID])
{
myOutcome = par.matchOutcome;
}
}
if (m.status != GKTurnBasedMatchStatusEnded && myOutcome != GKTurnBasedMatchOutcomeQuit)
{
if ([m.currentParticipant.playerID
isEqualToString:[GKLocalPlayer localPlayer].playerID])
{
[myMatches addObject:m];
}
else
{
[otherMatches addObject:m];
}
}
else
{
[endedMatches addObject:m];
}
}
// 6
allMyMatches = [[NSArray alloc]initWithObjects:myMatches,otherMatches,endedMatches, nil];
NSLog(@"%@",allMyMatches);
[self.tableView reloadData];
}
}];
任何想法为什么会发生这种情况?