你好我正在聊天应用程序,正在发送文件给朋友如Skype,当我有文件传输请求该方法应该返回BOOL值。所以显示alertview后,在等待用户响应我如何等待语句执行,直到UIAlertview按钮点击
我的代码,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;
}
}
}
有你阅读任何围绕'UIAlertView'(https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertView_Class/index.html)或'UIAlertViewDelegate'的Apple文档? – Popeye 2014-10-28 07:54:58
这可能是因为它在任何应用程序中都不会起作用。什么是'buttonClicked'?这宣布在哪里?如果你有更多的代码,那么你需要分享你有什么我们不介意读者 – Popeye 2014-10-28 08:17:00
做好了我的问题/答案的所有downvotes。多么可悲,把你标示给版主。 – Popeye 2014-10-28 08:55:29