【问题标题】:MBProgressHUD display TwitterMBProgressHUD 显示 Twitter
【发布时间】:2012-04-01 08:26:12
【问题描述】:

我有 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";

}

【问题讨论】:

  • 您要将 MBProgressHUD 添加到哪个视图?不过,这将有助于查看您的代码。
  • 您需要向我们展示一些代码来帮助您。

标签: iphone ios twitter uiwebview mbprogresshud


【解决方案1】:

您正在同步下载主线程中的图像,从而阻止 UI 更新。有关详细说明和可能的解决方法,请参阅 this answer

不过,对您来说最好的选择是使用类似 NSURLRequest 的方式异步下载图像(参见 showURL: exampledelegate callbacks)。

【讨论】:

    猜你喜欢
    • 2011-07-28
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 1970-01-01
    相关资源
    最近更新 更多