我实现了游戏套件。现在一切正常。但如果用户按下发送数据将立即发送到其他iPhone/iPod/iPad,它会立即写入。如何获得UIAlertView的结果?
所以现在我想实现接收器的确认屏幕。
在我的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");
}
}
您是否看到问题?我能做什么??
使用给定的代码,我没有看到有必要在`UIAlertView`中设置`delegate to self`。 – Mahesh 2011-01-09 13:58:50