2016-05-16 61 views
0

在我的應用程序我試圖使用滑塊使用LWSlideShow LWSlideShow 圖像的來源從我的服務器嘗試解決方案後取回here我卡住了錯誤,說不平衡的呼叫這意味着我提出了一個模式的觀點,沒有完成他的動畫解決這個問題後,通過把動畫放在沒有splashView,我將出現在圖像下載之前將被解僱這裏是我的代碼作進一步解釋:顯示啓動畫面,而下載圖像從服務器在ios

- (IBAction)goDownload { 

    UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Splash"]; 
     [self.navigationController presentViewController:vc animated:YES completion:nil]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     NSMutableArray *array = [@[] mutableCopy]; 
     LWSlideItem *item = [LWSlideItem itemWithCaption:@"" 
               imageUrl:@"http://code-bee.net/geeks/images/cover-1.jpg"]; 
     [array addObject:item]; 
     item = [LWSlideItem itemWithCaption:@"" 
            imageUrl:@"http://code-bee.net/geeks/images/cover-2.jpg"]; 
     [array addObject:item]; 
     item = [LWSlideItem itemWithCaption:@"" 
            imageUrl:@"http://code-bee.net/geeks/images/cover-3.jpg"]; 
     [array addObject:item]; 





     LWSlideShow *slideShow = [[LWSlideShow alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 120)]; 

     slideShow.autoresizingMask = UIViewAutoresizingFlexibleWidth; 

     //slideShow.delegate = self; 
     [self.view addSubview:slideShow]; 
     slideShow.slideItems = array; 



     if ([slideShow.slideItems count] == [array count]) { 
      [self dismissViewControllerAnimated:YES completion:nil]; 
     } 



    }); 









} 





// 
//-(void)viewWillAppear:(BOOL)animated 
//{ 
// 
// UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Splash"]; 
// [self.navigationController presentViewController:vc animated:YES completion:nil]; 
//} 




- (void)viewDidLoad { 
    [super viewDidLoad]; 




    [self goDownload]; 
    } 

你也可以從代碼中看到,我也嘗試使用viewWillAppear同樣的事情發生了什麼我wan t是什麼時候下載圖像splashView需要被解僱我不知道我在做什麼錯

回答

3

在viewDidAppear(如viewDidLoad,viewWillAppear)之前隨時從VC運行該代碼將導致您描述的問題。但是,您可能不希望幻燈片放映視圖出現 - 即使是在一瞬間 - 直到您完成提取資產。這是一個常見問題。

解決方案是意識到「閃屏」和網絡任務不僅僅是序言,它們與幻燈片一樣是應用程序的一部分。

編輯 讓那個Splash vc成爲故事板中應用的初始視圖控制器。眼下,幻燈片播放VC大概是這樣的:

enter image description here

取消選中「在初始視圖控制器」複選框,找到你的飛濺視圖控制器(在同一個故事板,我希望),並檢查它的框成爲初始視圖控制器。現在你的應用程序將啓動飛濺VC,就像你想要的一樣。

當飛濺vc完成時,它可以呈現幻燈片放映vc,或者它甚至可以用幻燈片放映自己替換爲應用窗口的根。

要更換UI,我用這個片段的變化......

// in the splash vc, after all of the asset loading is complete 

// give what used to be your initial view controller a storyboard id 
// like @"MySlideShowUI" 

UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MySlideShowUI"]; 

UIWindow *window = [UIApplication sharedApplication].delegate.window; 
window.rootViewController = vc; 

[UIView transitionWithView:window 
        duration:0.3 
        options:UIViewAnimationOptionTransitionCrossDissolve 
       animations:nil 
       completion:nil]; 
+0

可以提供有關如何解決我的問題 –

+0

詳情哪一部分沒有我不解釋還不夠嗎? – danh

+0

使該Splash vc成爲故事板中應用程序的初始視圖控制器。完成後,它可以呈現幻燈片放映vc,或者甚至可以將其自身(以幻燈片放映)替換爲應用程序窗口的根。 –