2012-11-22 31 views
4

我在我的應用程序上打開Twitter撰寫視圖,但屏幕顯示時間太長!如何使SLComposeViewController的presentViewController更快?

我開始當用戶點擊Twitter的按鈕使用下面的代碼:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) 
{ 

    SLComposeViewController *tweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; 

    [tweet setInitialText:@"initial text "]; 


    [self presentViewController:tweet animated:YES completion:^ 
    { 

    }]; 
} 

但它需要幾秒鐘5和8之間,以顯示在屏幕!對我而言,這太長了,我看到了即時的應用程序。這不是我的應用程序的問題,因爲我已經創建了一個只有這個功能的新項目,它也是一樣的。

所以我認爲拖延是在屏幕被實例化的時刻,所以我已經決定宣佈我的鳴叫屏幕上我的頭和移動這部分的viewDidAppear:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) 
{ 

tweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; 

[tweet setInitialText:@"initial text "]; 

,並在按鈕方法是這樣的:

if(tweet) 
[self presentViewController:tweet animated:YES completion:^ 
{ 

}]; 

但它沒有得到更快。我正在使用iPhone 4,並且我有一些應用程序可以非常快地創建Twitter撰寫屏幕,有人知道如何做到這一點嗎?

+0

除非有線程消耗一段代碼,否則不應該發生這種情況。你在模擬器中啓用了慢動畫嗎? –

+0

嘿@ 0x7fffffff ..謝謝你的回覆..我甚至不知道這是可以啓用慢動畫.. =)無論如何,我正在使用該設備來測試.. –

+0

是的,它可以真正有幫助,當你'重新嘗試確保某些動畫是正確的。有沒有任何代碼直接在你的函數上面呢? –

回答

0

我有同樣的問題 - 這讓我瘋狂。我通過主隊列上的dispatch_async修復了它

// Perform this on the main queue 
__weak __typeof(self) weakSelf = self; 

dispatch_async(dispatch_get_main_queue(), ^{ 
    __strong __typeof(self) strongLocalSelf = weakSelf; 


     SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 
     [controller setInitialText:@"Share message"]; 
     [controller addURL:@"http://www.someURL.com"]; 
     [strongLocalSelf presentViewController:controller animated:NO completion:nil]; 


}); 
+0

不幸的是,這不起作用。 – mkeremkeskin

0

這個問題一直困擾着我以及整整一天!最後,我得到一些技巧,使SLComposeViewController顯得更快。它似乎是我第一次加載SLComposeVC時,SLComposer將在主線程中佔用大量資源,但在此之後,它將顯示完全正常,無延遲...所以我想也許我們需要加載SLCompose鑑於我們視圖控制器(只是加載視圖)和中提琴...的SLComposerView將直接呈現到視圖...

在你的appdelegate只需添加該代碼

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ .... 

//loading the view...make twitter share dialog appear with no dellay 
    if(NSClassFromString(@"SLComposeViewController") != nil){ 
     SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; 
     [composeViewController view]; 
    } 
    ... 
} 
  • 對不起,如果我的英語不完美,我不是本地人。
+0

這似乎沒有幫助不幸的 –