我实施了游戏套件。现在一切正常。但是如果用户按下发送数据会立即发送到其他iphone / ipod / ipad,它会立即写入。
所以现在我想为接收器实现一个确认屏幕。
在我的receiveData方法中(来自gamekit)我有一个数组。如果用户按下yes,则数组将被写入文件。如果没有将其写入文件中。
#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");
}
}
你看到了问题吗?我能做什么??
答案 0 :(得分:2)
dict创建为自动释放,因此在UIAlertView显示期间将被删除。
答案 1 :(得分:0)
您的CancelButton索引是== 0;
cancelButtonTitle:@“取消”otherButtonTitles:@“OK”,nil
好像,你的OK按钮索引是1。