cocos2dbeginner
cocos2dbeginner

Reputation: 2207

How to get a UIAlertView's result?

I implemented the gamekit. All works fine now. But if the user presses on send the data will instantly send to the other iphone/ipod/ipad and it will instantly written.

So now i wanted to implemenr a confirm screen for the receiver.

In my receiveData method (from the gamekit) i have an array. If the user presses yes the array will be written into a file.if not it wont be written into a file.

    #pragma mark -
    #pragma mark - GKreceiveData
    - (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context
    {
        NSDictionary *dict = [NSKeyedUnarchiver  unarchiveObjectWithData:data];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Incoming Set" message:[NSString stringWithFormat:@"%@ wants to send you a Set named: \n\n %@",[session displayNameForPeer:peer], [dict valueForKey:@"SetName"]] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        [alert show];
        [alert release];




    }
    - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
        // the user clicked one of the OK/Cancel buttons
        if (buttonIndex == 0)
        {
            //NSLog(@"ok");
  //this should happen if the user presses on ok on the alertview.
        [dataArray addObject:dict]; //i can't acess "dict"


        }
        else
        {
            //NSLog(@"cancel");
        }
    }

Do you see the problem?? What can I do??

Upvotes: 0

Views: 1751

Answers (2)

Nickolay Olshevsky
Nickolay Olshevsky

Reputation: 14160

dict is created as autorelease, so it will be deleted during UIAlertView show up.

Upvotes: 2

0xDE4E15B
0xDE4E15B

Reputation: 1294

Your CancelButton's index is == 0;

cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil

Seems, that your OK button index is 1.

Upvotes: 0

Related Questions