1

我有UIViewController一个UITableView在里面。我UIView在上面添加了一个子视图。当我在子视图上按下其中一个UIButtons 时,会出现明显的滞后。我怎样才能让它更快?

观看视频:http ://www.youtube.com/watch?v=KWy6NrZUeqA&feature=youtu.be

- (IBAction)tweetThat:(id)sender {
    [MBProgressHUD showHUDAddedTo:self.socialMediaView animated:YES];

    dispatch_queue_t queueOne=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_sync(queueOne, ^{
        NSString *tweetBody=@"BLABLABLATweet";

        if ([TWTweetComposeViewController canSendTweet])
        {
            TWTweetComposeViewController *tweetSheet = 
            [[TWTweetComposeViewController alloc] init];
            [tweetSheet setInitialText:tweetBody];
            dispatch_async(dispatch_get_main_queue(), ^{
                [MBProgressHUD hideHUDForView:self.controllerView animated:YES];
                [self presentModalViewController:tweetSheet animated:YES];
            });
        }
        });
}
4

3 回答 3

1

我已经使用了您在上面尝试的调度方法,但做了一些更改。它确实使体验变得更好。“loadingView”正如其名,只是在推文视图出现之前显示的加载视图。

    loadingView.hidden = NO;
    [loadingView setNeedsDisplay];
    if ([TWTweetComposeViewController canSendTweet])
    {
        double delayInSeconds = 0.5;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            TWTweetComposeViewController *tweet = [[TWTweetComposeViewController alloc]init];
            [tweet setInitialText:@"I'm using a new app called TickTalk to help my speaking cadence. Check it out!"];
            [tweet addURL:[NSURL URLWithString:@"http://www.ticktalkapp.com"]];
            TWTweetComposeViewControllerCompletionHandler
            completionHandler =
            ^(TWTweetComposeViewControllerResult result) {
                switch (result)
                {
                    case TWTweetComposeViewControllerResultCancelled:
                        NSLog(@"Twitter Result: canceled");
                        break;
                    case TWTweetComposeViewControllerResultDone:
                        NSLog(@"Twitter Result: sent");
                        break;
                    default:
                        NSLog(@"Twitter Result: default");
                        break;
                }
                loadingView.hidden = YES;
                [self dismissModalViewControllerAnimated:YES];
            };
            [tweet setCompletionHandler:completionHandler];
            [self presentModalViewController:tweet animated:YES];
        });
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sorry" message:@"Your device is not setup to tweet" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        loadingView.hidden = YES;
    }
于 2012-08-23T01:21:39.870 回答
0

滞后来自TWTweetComposeViewController. 您对此无能为力,因为它是系统优化。您可能会注意到第二次和第三次按下按钮时延迟消失了。

于 2012-08-07T15:58:28.897 回答
0

将您的 dispatch_sync 更改为 dispatch_async。如果您要锁定 UI 直到它返回,那么调度到后台有什么意义。

于 2012-08-23T01:24:38.433 回答