0

我有一个名为 MatchmakingServer 的类有一个方法如下:

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state

{

switch (state)
{
    case GKPeerStateAvailable:
        break;

    case GKPeerStateUnavailable:
        break;

        // A new client has connected to the server.
    case GKPeerStateConnected:
        if (_serverState == ServerStateAcceptingConnections)
        {
            if (![_connectedClients containsObject:peerID])
            {
                NSString *peerID2 =[self displayNameForPeerID:peerID];
                self.PeerId=peerID;
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops:("
                                                                message:[NSString stringWithFormat:@"%@:%@ %@",@"device",peerID2,@"want to join your session"]
                                                               delegate:self
                                                      cancelButtonTitle:@"NO"
                                                      otherButtonTitles:nil];


                [_connectedClients addObject:peerID];
                NSLog(@"the orginal peerID %@",peerID);
                [self.delegate matchmakingServer:self clientDidConnect:peerID];
            }
        }

@interface MatchmakingServer : NSObject <GKSessionDelegate,UIAlertViewDelegate>

为什么 alertView 不调用 clickedButtonAtIndex 的任何想法

4

2 回答 2

0

您没有在屏幕上显示警报视图,您只是在初始化它。插入

[alert show];

在初始化代码之后,你应该没问题。

于 2012-11-01T14:45:35.583 回答
0

您需要调用[alert show];方法并UIAlertViewDelegateUIViewController.h文件中采用。

于 2012-11-01T14:54:47.427 回答