0

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??

cocos2dbeginner
  • 2,185
  • 1
  • 31
  • 58
  • With the given code, I don't see there is a need to set your `delegate to self` in `UIAlertView`. – Mahesh Jan 09 '11 at 13:58

2 Answers2

2

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

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48
0

Your CancelButton's index is == 0;

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

Seems, that your OK button index is 1.

0xDE4E15B
  • 1,284
  • 1
  • 11
  • 25