I'm trying to make my own Game Center interface, because I find the pool table style of the default one clashes with the style of the rest of my app.
When a player wants to start a game with a friend, my interface pops up an alert view, shows a spinner while it fetches their friends list, and then adds a button to the alert view for each friend.
Here's the code:
The spinner shows up and hides fine, but the alert view doesn't add the buttons properly. Rather than lay them out nicely, it just throws the buttons with black text and no background in the top left corner.
Any suggestions on why it's not working or what I could do different?
When a player wants to start a game with a friend, my interface pops up an alert view, shows a spinner while it fetches their friends list, and then adds a button to the alert view for each friend.
Here's the code:
Code:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Play with Someone Online"
message:@"Loading Game Center Friends...\n\n\n"
delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Play with Anyone", nil];
[alert show];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.frame = CGRectMake(123.0, 70.0, 37.0, 37.0);
[spinner startAnimating];
[alert addSubview:spinner];
[alert release];
[[GKLocalPlayer localPlayer] loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error)
{
[spinner removeFromSuperview];
if ([friends count] <= 0 || friends == nil)
{
[alert setMessage:@"You have no friends on Game Center, how sad."];
[alert addButtonWithTitle:@"Find Friends by Email"];
}
else
{
[alert setMessage:@""];
[GKPlayer loadPlayersForIdentifiers:friends withCompletionHandler:^(NSArray *players, NSError *error)
{
[players enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop)
{
GKPlayer *player = (GKPlayer *)obj;
[alert addButtonWithTitle:player.alias];
}];
}];
[alert addButtonWithTitle:@"Find More Friends by Email"];
}
}];
}
The spinner shows up and hides fine, but the alert view doesn't add the buttons properly. Rather than lay them out nicely, it just throws the buttons with black text and no background in the top left corner.
Any suggestions on why it's not working or what I could do different?