Log*_*ire 5 iphone objective-c ios objective-c-blocks ios6
我正在开发一款基于回合制的iOS游戏,并尝试填充玩家参与的游戏列表.
for (unsigned i = 0; i < [matches count]; i++)
{
// Only load data for games in progress.
// NOTE: Might want to handle finished games later.
if ([matches[i] status] != GKTurnBasedMatchStatusEnded)
{
// Send off another block to retrieve the match's data.
[(GKTurnBasedMatch*)matches[i] loadMatchDataWithCompletionHandler: ^(NSData *matchData, NSError *error)
{
// Prepare the game.
Game* game;
if (matchData.length == 0)
{
// If the match data is empty, this is a new game. Init from scratch.
game = [[Game alloc] init];
}
else
{
// Otherwise, unpack the data and init from it.
game = [NSKeyedUnarchiver unarchiveObjectWithData:matchData];
}
game.match = matches[i];
// Load the displayNames for the players.
bool lastIndex = i == ([matches count] - 1);
[self loadPlayerIdentifiersForGame:game intoArray:blockGames lastIndex:lastIndex];
}];
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我遇到了一个问题,我不能用索引标记每个块.也就是说,i总是0在块执行时.有没有办法可以确保该块i在启动时知道什么是WAS?
UITableView我通过这样做回避了如果上一场比赛结束我将不会重新加载的问题:
GKTurnBasedMatch* match;
for (int j = ([matches count] - 1); j >= 0; j --)
{
match = matches[j];
if (match.status != GKTurnBasedMatchStatusEnded)
break;
}
bool lastIndex = (matches[i] == match);
[self loadPlayerIdentifiersForGame:game intoArray:blockGames lastIndex:lastIndex];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
108 次 |
| 最近记录: |