我有 UIWebView,它已经从互联网上加载了一张图片。我有一个打开 UIActionSheet 的按钮,让您可以选择在 UIWebView 中发送这张图片。如果您在 UIActionSheet 中点击 Tweet,它会消失并且您会再次看到 UIWebview。在后台,图片正在从互联网加载以将其附加到推文中。这可能需要一些时间,具体取决于图像大小。我现在想向用户显示他知道发生了什么的信息。我想在用户等待 Twitter 控制台出现时显示 MBProgressHUD。当按下按钮并且 UIActionSheet 消失但它没有出现时,我尝试启动 HUD。当 Twitter 控制台出现时,它会在后台出现。这有点晚了。那么启动/停止 HUD 的最佳位置是什么?谢谢
- (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
{
[self hudTweet];
[self tweet];
}
- (void) tweet {
if ([TWTweetComposeViewController canSendTweet])
{
TWTweetComposeViewController *tweetSheet =
[[TWTweetComposeViewController alloc] init];
[tweetSheet setInitialText:
@"Tweeting from "];
NSString *fullURL = beverageViewString;
NSURL *url = [NSURL URLWithString:fullURL];
NSString *paths = NSTemporaryDirectory();
NSError *error;
if (![[NSFileManager defaultManager] fileExistsAtPath:paths])
[[NSFileManager defaultManager] createDirectoryAtPath:paths withIntermediateDirectories:NO attributes:nil error:&error];
NSString *filePath = [paths stringByAppendingPathComponent:[self.title stringByAppendingFormat:@".jpeg"]];
NSData *jpegFile = [NSData dataWithContentsOfURL:url];
[jpegFile writeToFile:filePath atomically:YES];
[tweetSheet addImage:[UIImage imageWithContentsOfFile:filePath]];
[self presentModalViewController:tweetSheet animated:YES];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Sorry"
message:@"You can't send a tweet right now because your account isn't configured"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
- (void) hudTweet {
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
[self.view.window addSubview:HUD];
HUD.delegate = self;
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = @"Loading";
HUD.detailsLabelText = @"updating data";
}