플레이어가 내 tableView를 채우는 데 참여하는 턴 기반 게임을 가져 오려고합니다. 플레이어가 참여하는 턴 기반 게임 얻기
이
은 게임을 끌어 내 기능입니다 :- (void) loadMatchDataWithArray:(NSMutableArray*)currentGames Flag:(bool*)returned
{
NSMutableArray* __block blockGames = currentGames;
bool* __block blockReturn = returned;
[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error)
{
if (matches)
{
for (int i = 0; i < matches.count; i++)
{
[(GKTurnBasedMatch*)matches[i] loadMatchDataWithCompletionHandler: ^(NSData *matchData, NSError *error)
{
int size = [matchData length];
if (size != 0)
{
Game* game = [NSKeyedUnarchiver unarchiveObjectWithData:matchData];
[blockGames addObject:game];
}
else
{
Game* game = [[Game alloc] init];
[blockGames addObject:game];
game.activePlayer = [GKLocalPlayer localPlayer];
}
*blockReturn = true;
}];
}
}
else
{
*blockReturn = true;
}
}];
}
을 그리고 내가 전화 곳이다 :
- (void)viewDidLoad
{
[super viewDidLoad];
[[self tableView]
setBackgroundView:[[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"iPhoneBackground-568h"]]];
bool* returned = false;
[[GKMatchHelper sharedInstance] loadMatchDataWithArray:currentGames Flag:returned];
while (!returned);
[self.tableView reloadData];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
슬프게도, 이것은 단지 나에게 검은 색 빈 화면을 제공하고 반환되지 않습니다. 블록이 돌아 왔을 때를 감지하고 그때까지 로딩 스피너를 표시 할 수있는 방법이 있습니까? 그 시점에서 테이블을 다시로드합니까?
편집 : 내 코드를 수정하여 MainMenuViewController 내에서 기능을 가져 왔지만 이제는 빌드했지만 데이터를 표시하지 않습니다.
- (void) loadMatchData
{
NSMutableArray* __block blockGames = currentGames;
MainMenuViewController* __weakSelf = self;
[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error)
{
if (matches)
{
for (int i = 0; i < matches.count; i++)
{
[(GKTurnBasedMatch*)matches[i] loadMatchDataWithCompletionHandler: ^(NSData *matchData, NSError *error)
{
int size = [matchData length];
if (size != 0)
{
Game* game = [NSKeyedUnarchiver unarchiveObjectWithData:matchData];
[blockGames addObject:game];
}
else
{
Game* game = [[Game alloc] init];
[blockGames addObject:game];
game.activePlayer = [GKLocalPlayer localPlayer];
}
[__weakSelf.tableView reloadData];
}];
}
}
[__weakSelf.tableView reloadData];
}];
[__weakSelf.tableView reloadData];
}
그리고 지금 내있는 viewDidLoad에 난 그냥 전화 :
[self loadMatchData];
먼저 'iPhoneBackground-568h'에서 파일 확장자가 누락되었습니다. – Popeye
그것은 PNG입니다. –
정말입니까? 그 이론을 시험해 볼 수도 있습니다. 그것이 필요하지 않다면 그것은 차이를 만든다. 나중에 참조 할 때 알아두면 좋습니다. – Popeye