简体   繁体   English

Xcode子导航视图

[英]Xcode sub navigation views

Does anyone know of any good tutorials for the following please? 有人知道以下任何好的教程吗?

Im new to Xcode and dont know where to start with this. 我是Xcode的新手,不知道从哪里开始。

I have a ViewController that is the root View and has 6 navigation buttons (UIButton) on it. 我有一个ViewController,它是根视图,上面有6个导航按钮(UIButton)。 Depending on which button that is clicked, the user will see a sub-navigation View of that section with further button options on it. 根据所单击的按钮,用户将看到该部分的子导航视图,上面带有其他按钮选项。

So eg top level will have buttons Where to Eat, What to Do... Then clicking on Where to Eat will show Restaurants, Fast Food ....etc 因此,例如顶层将具有“在哪里吃饭,做什么”按钮,然后单击“在哪里吃饭”将显示餐厅,快餐...等

I would like to do this programatically. 我想以编程方式执行此操作。 I can do it using Storyboards and using multiple views, but it gets very messy as there are a lot of views on the screen eventually. 我可以使用情节提要板和使用多个视图来完成此操作,但是由于最终屏幕上有很多视图,所以它变得非常混乱。

I have followed a tutorial HERE on how it is done for TableViewControllers, but I need something similar for buttons. 我已经在这里按照教程完成了TableViewControllers的操作,但是按钮也需要类似的东西。

Im not sure what this function is called - have been searching for sub-navigation for the last while but nothing matches what I need to accomplish this. 我不确定该函数的名称-上一阵子一直在寻找子导航,但是没有任何东西可以满足我的需要。

Check out UIViewController's method presentViewController:animated:completion: method. 查看UIViewController的方法presentViewController:animated:completion:方法。 It is available in iOS 5.0 and up. 它在iOS 5.0及更高版本中可用。 Let's say you have one of the button's linked to run the buttonOneActivated: method: 假设您具有链接的按钮之一来运行buttonOneActivated:方法:

-(IBAction)buttonOneActivated:(id)sender
{
    UISubViewController *subViewController = [[UISubViewController alloc] init];

    [self presentViewController:subViewController
                       animated:YES
                     completion:NULL];
}

And in UISubViewController's implementation, let's say you have another button in order to return to the parent: 在UISubViewController的实现中,假设您有另一个按钮可以返回到父级:

-(IBAction)returnToParent:(id)sender
{
    [[self presentingViewController] dismissViewControllerAnimated:YES
                                                        completion:NULL];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM