Iphone 按下按钮时iAction滞后

Iphone 按下按钮时iAction滞后,iphone,Iphone,我有一个UIViewController,里面有一个UITableView。我在上面添加了一个UIView作为子视图。当我按下子视图上的ui按钮之一时,有明显的延迟。我如何使它更快 见视频: 滞后来自tweetcomposeviewcontroller。你对此无能为力,因为这是一个系统优化。您可能会在第二次和第三次按下按钮时注意到延迟消失。延迟来自tweetcomposeviewcontroller。你对此无能为力,因为这是一个系统优化。您可能会注意到第二次和第三次按下按钮时,延迟消失了。我使用

我有一个
UIViewController
,里面有一个
UITableView
。我在上面添加了一个
UIView
作为子视图。当我按下子视图上的
ui按钮之一时,有明显的延迟。我如何使它更快

见视频:


滞后来自
tweetcomposeviewcontroller
。你对此无能为力,因为这是一个系统优化。您可能会在第二次和第三次按下按钮时注意到延迟消失。

延迟来自
tweetcomposeviewcontroller
。你对此无能为力,因为这是一个系统优化。您可能会注意到第二次和第三次按下按钮时,延迟消失了。

我使用了您在上面尝试过的调度方法,但有一些更改。这真的让体验好多了。“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;
    }

我使用了您在上面尝试过的分派方法,但做了一些更改。这真的让体验好多了。“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;
    }

将调度同步更改为调度异步。如果要锁定UI直到其返回,则将其发送到后台有什么意义。

将发送同步更改为发送异步。如果要锁定UI直到它返回,那么将其发送到后台有什么意义。

是的,我注意到下次它会加快速度。但是为什么MBHUD也会延迟呢?MBProgressHUD是在主线程上调用的第一个对象,而tweetcomposeviewcontroller在后台线程上是alloc'd和init'd。还有,“系统优化”是什么意思?我不确定。我自己很少使用
dispatch\u queue
s,当我使用
performSelectorOnBackgroundThread
时,我通常会将
performSelectorOnBackgroundThread
作为一个集合来使用,并忘记某种方法。至于系统优化,我想说的是由于
tweetcomposeviewcontroller
造成的延迟,我认为您无法修复它。苹果不得不这么做。是的,我注意到它下次会加速。但是为什么MBHUD也会延迟呢?MBProgressHUD是在主线程上调用的第一个对象,而tweetcomposeviewcontroller在后台线程上是alloc'd和init'd。还有,“系统优化”是什么意思?我不确定。我自己很少使用
dispatch\u queue
s,当我使用
performSelectorOnBackgroundThread
时,我通常会将
performSelectorOnBackgroundThread
作为一个集合来使用,并忘记某种方法。至于系统优化,我想说的是由于
tweetcomposeviewcontroller
造成的延迟,我认为您无法修复它。苹果必须这样做。