在多个故事板中实现SWRevealViewConroller库(滑出菜单)

时间:2015-05-28 04:52:47

标签: ios swift storyboard segue swrevealviewcontroller

我正在努力实现VideoTutorial中给出的SWRevealViewController Library,我成功地做到了这一点,但我不想在1个故事板上的所有内容,我想在2个故事板中分解< / p>

  

AppDelegate 代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    storyboard = UIStoryboard(name: "MenuDrawer", bundle: nil)           
    initialViewController = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! UIViewController

    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()
    return true    
}

Rightnow MenuDrawer故事板包含所有内容

  
      
  1. SWRevealViewCOntroller
  2.   
  3. TableViewController
  4.   
  5. NavigationController
  6.   
  7. RootViewController的
  8.   

以及在库中定义的segues:

  
      
  1. segue1 (sw_rear) : between SWRevealViewController --> TableViewController
  2.   
  3. segue2 (sw_front) : between SWRevealViewController --> NavigationController
  4.   

现在我想在不同的故事板中使用3和4。但是当我将3和4移动到不同的故事板时,如何在故事板中创建segue 2

4 个答案:

答案 0 :(得分:1)

我不确定我是否理解你的问题,但你可以尝试这个来重新启动你的第二个故事板并从那里加载你的navigationViewController。

// One time during setup.
GLuint readFboId = 0;
glGenFramebuffers(1, &readFboId);
glBindFramebuffer(GL_READ_FRAMEBUFFER, readFboId);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                       GL_TEXTURE_2D, tex, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);

// Every time you want to copy the texture to the default framebuffer.
glBindFramebuffer(GL_READ_FRAMEBUFFER, readFboId);
glBlitFramebuffer(0, 0, texWidth, texHeight,
                  0, 0, winWidth, winHeight,
                  GL_COLOR_BUFFER_BIT, GL_LINEAR);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);

答案 1 :(得分:1)

据我所知,你不需要再次推动3和4上的segue 2.你需要的是在segj 2上引用新视图(3和4)。在Obj-c中将是那样:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SWRevealViewController *view = [mainStoryboard instantiateViewControllerWithIdentifier:identifier];
[view setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self.navigationController pushViewController:view animated:YES];

其中&#34; self&#34;是ViewController,其中创建了segue 2。 我希望已经回答了你的问题。

答案 2 :(得分:1)

首先尝试这个制作另一个故事板并添加您需要的内容,然后调用另一个故事板 AppDelegate代码:

func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

var storyboard = UIStoryboard(name: "MenuDrawer", bundle: nil)   
var storyboard1 = UIStoryboard(name: "NewStoryBoardName", bundle: nil)          
var initialViewController = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! UIViewController
var initialViewController1 = storyboard1.instantiateViewControllerWithIdentifier("SWRevealViewController") as! UIViewController

self.window?.rootViewController = [initialViewController,initialViewController1]
self.window?.makeKeyAndVisible()
return true

}

答案 3 :(得分:1)

您无法使用Interface Builder在故事板之间创建segue。 它只能以编程方式进行,例如:

let storyBoardTwo = UIStoryboard(name: "storyBoardTwo", bundle: nil)

// Pick a view controller using it's identifier string set in Interface Builder.
let myVC = storyBoardTwo.instantiateViewControllerWithIdentifier("aViewController") as! UIViewController // Or use more specific (custom) type

// Push it to the navigation controller
self.navigationController.pushViewController(myVC, animated: true)

pushViewController只会将myVC放在首位。这段代码就是segue最终会做的事情。您可以将此代码放在现有ViewController的任何位置,按钮点击IBAction或任何需要的位置。

如果推送的ViewController有任何segues(来自Storyboard或代码),它们仍将按预期工作。

当然,如果您希望以编程方式从同一个Storyboard加载ViewController,这当然有效。