2016-12-06 174 views
0

我一直在使用SWRevealViewController庫很長一段時間沒有問題,我真的很喜歡它! 這一次,我已經將它添加到一個項目,所以這是我做了什麼:SWRevealViewController導致無限循環初始化

  • 我已經採取了「RevealControllerExample」樣本。
  • 我已經直接將SWRevealViewController.h/.m複製到我的項目中。
  • 我已經直接將FrontViewController.h/.m/.xib複製到我的項目中我已經直接將RearViewController.h/.m/.xib複製到我的項目中,但是我刪除了didSelectRowAtIndexPath中的所有代碼(我並不需要它暫時)。
  • 我忽略了RightViewController,因爲我不需要它。
  • 我已經添加到我的AppDelegate:didFinishLaunchingWithOptions所有的初始化代碼,除了RightViewController之外,因爲我不需要它。

這是我怎麼有初始化代碼:

FrontViewController *frontViewController = [[FrontViewController alloc] init]; 
    RearViewController *rearViewController = [[RearViewController alloc] init]; 

    UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController]; 
    UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController]; 

    SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController]; 
    revealController.delegate = self; 


    self.swViewController = revealController; 

    self.window.rootViewController = self.swViewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 

當我啓動應用程序崩潰,這是因爲一個無限循環。這是調用堆棧:

...(here comes inifite calls to transitionFromViewController)... 
#36603 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36604 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36605 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36606 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36607 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36608 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36609 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36610 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36611 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36612 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36613 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683 
#36614 0x0011759c in __82-[SWRevealViewController _performTransitionOperation:withViewController:animated:]_block_invoke at /path/to/myproject/SWRevealViewController.m:1470 
#36615 0x0011757e in -[SWRevealViewController _performTransitionOperation:withViewController:animated:] at /path/to/myproject/SWRevealViewController.m:1497 
#36616 0x001137be in -[SWRevealViewController initWithRearViewController:frontViewController:] at /path/to/myproject/SWRevealViewController.m:635 
#36617 0x000e1ec0 in -[AppDelegate application:didFinishLaunchingWithOptions:] at /path/to/myproject/AppDelegate.m:35 

我已經直接測試了示例,當然它的工作原理。 我正在使用Xcode 8,並且正在編譯iOS 10.1。 我正在做的唯一的「不同」事情是我的應用程序只是風景,我不知道這是否會影響側面菜單。

它會發生什麼?

+0

您需要將'SWRevealViewController'集成到您的項目中,只需要左側導航? – vaibhav

+0

是的,就是。我需要一個左側導航。爲了達到同樣的目的,我多次使用這個庫,但沒有問題,但是這次我不知道它發生了什麼。 – Wonton

+0

其實我已經多次使用故事板做了這樣的事情,並沒有像'appdeleate'那樣編碼,如果你選擇的話,我可以一步一步發佈解決方案給你。 – vaibhav

回答

0

現在在左側滑動菜單中使用SWRevealViewController library代碼中的一些變化,這裏有一些棘手的步驟要遵循才能正確使用。

類配置:

  1. 添加一些類你的項目和它的故事板內以及download link

    • SWRevealViewController.h
    • SWRevealViewController.m
    • SidebarViewController.h
    • SidebarViewController.m
  2. 爲了創建前視圖和罕見的視圖,請參閱故事板配置。

  3. 要在菜單中添加更多viewControllers,首先需要創建可可類並添加以下代碼。

    • h文件內創建稍後用於導航側按鈕的IBOutlet中。
    • 進口"SWRevealViewController.h"

      @property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton; 
      
    • .m文件內添加以下代碼內viewDidLoad方法:

      // Change button color 
      _sidebarButton.tintColor = [UIColor colorWithWhite:0.1f alpha:0.9f]; 
      
      // Set the side bar button action. When it's tapped, it'll show up the sidebar. 
      _sidebarButton.target = self.revealViewController; 
      _sidebarButton.action = @selector(revealToggle:); 
      
      // Set the gesture 
      [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; 
      

Stroyboard配置:

  1. 爲了使前視圖viewController

    • 使用賽格瑞從Reveal View Controller連接任何vc,並選擇reveal view controller看到內部圖像:

      enter image description here

    • 然後必須設置標識符作爲sw_front的上述精確度見圖像: enter image description here

  2. 要配置其他viewController的菜單中,您必須將其從Sidebar scenevc's電池使用賽格瑞連接而無需像第一形象標識。

  3. 連接所有sidebarButtonIBOutlet之前自來水。

  4. 添加更多的viewController你需要補充細胞內Sidebar scene VC,使內部menuItems陣列一些變化SidebarViewController.m類中找到,但不忘記作出這樣的細胞identifire一樣menuItmes。

    menuItems = @[@"title", @"news", @"comments", @"map", @"calendar", @"wishlist", @"bookmark", @"tag", @"anotherVc_1", @"anotherVc_2"]; 
    

注意:您可以刪除SidebarViewController.mprepareForSegue方法,使獨立的VC對所有電池過渡,prepareForSegue方法處理賽格瑞傳輸被重定向用戶,以便同一個VC與差異的外觀。

希望這可以幫助你很多。

+0

謝謝vaibhav!我一直在解決這個問題,可能是因爲我沒有能夠從故事板到ViewControllers正確地調整這個解決方案。我終於決定使用另一個側面菜單庫和它的工作了(這個庫是LGSideMenuController)。無論如何非常感謝你! – Wonton

+0

實際上遷移到另一個解決方案是一個很好的做法,無論如何它的選擇和感謝您的反饋。 – vaibhav