我的代码是,alertview显示,但UI已被阻止
-(BOOL)incommingFileRequest:(XMPPIQ *)inIq
{
NSXMLElement *si = [inIq elementForName:@"si"];
NSXMLElement *file = [si elementForName:@"file"];
NSDictionary *dic = [file attributesAsDictionary];
fileId = [inIq attributeStringValueForName:@"id"];
NSLog(@"---filename--- %@",[file attributeForName:@"name"]);
NSString *name = [NSString stringWithFormat:@"%@ \n %@ ",[dic objectForKey:@"name"],[ self transformedValue:[dic objectForKey:@"size"]]];
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Incommming File"
message:name
delegate:self
cancelButtonTitle:@"Reject"
otherButtonTitles:@"Accept", nil];
alrt.tag = 1111;
[alrt show];
while (buttonClicked == -1) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
if (buttonClicked == 1) {
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~YES");
return YES;
} else {
NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~NO");
return NO;
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertview.tag == 1111){
if (buttonIndex == 0){
buttonClicked = buttonIndex;
}
}
}
答案 0 :(得分:2)
让ViewController实现UIAlertViewDelegate
协议并实现方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Do whatever you need to do after the alertView closes, depending on button indices
if(alertview.tag == 1111){
if (buttonIndex == 0){
// First Button pressed
} elif (buttonIndex == 1) {
// Response if second button pressed
}
}
// etc etc
}