你好我正在聊天應用程序,正在發送文件給朋友如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