xcode iOS 版 Fragments
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18895158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS version of Fragments
提问by heyred
Can anyone tell me what the best way to do the following is in Xcode (iPhone).
谁能告诉我在 Xcode (iPhone) 中执行以下操作的最佳方法是什么。
I have a main navigation screen with some buttons on it. When the user clicks any of the buttons they are taken to a sub-navigation screen with more option buttons on it. Here they click whichever button and are taken to a list of options. Clicking on any list option will display a screen with some information to the user. Each one of these screen ( no matter what section of the app you're in) will look the same. Only text and images on these screens will change.
我有一个主导航屏幕,上面有一些按钮。当用户单击任何按钮时,他们将被带到带有更多选项按钮的子导航屏幕。在这里,他们单击任意按钮并进入选项列表。单击任何列表选项将向用户显示包含一些信息的屏幕。这些屏幕中的每一个(无论您在应用程序的哪个部分)看起来都一样。只有这些屏幕上的文本和图像会发生变化。
I have enclosed a diagram that might explain it better. What is the best way to handle this in Xcode? I have tried doing it all in Stroyboard as I'm new to Objective C but just the sheer amount of individual pages is slowing my machine down to a crawl. So a rethink is required.
我附上了一张图表,可以更好地解释它。在 Xcode 中处理这个问题的最佳方法是什么?我已经尝试在 Stroyboard 中完成所有操作,因为我是 Objective C 的新手,但只是单个页面的绝对数量使我的机器慢下来。所以需要重新思考。
I am also doing an Android version of this app and I'm using Fragments for this. Can anyone please help?
我也在做这个应用程序的 Android 版本,我正在为此使用 Fragments。有人可以帮忙吗?
EDIT: Just got to my devel machine and this is what I have been doing so far. I realise now this is the complete wrong way to do it. I have created a view controller for each "screen" if you like.
编辑:刚到我的开发机器,这就是我迄今为止一直在做的事情。我现在意识到这是完全错误的方法。如果您愿意,我已经为每个“屏幕”创建了一个视图控制器。
So I just create one view controller for all "screen" of e.g. Individual Page as per diagram and then add the text dynamically depending on what screen is selected? Can anyone point me in the direction of a tutorial or what I need to be searching for? I have no idea where to start with this using Xcode.
所以我只是根据图表为例如单个页面的所有“屏幕”创建一个视图控制器,然后根据选择的屏幕动态添加文本?任何人都可以指出我的教程方向或我需要搜索的内容吗?我不知道从哪里开始使用 Xcode。
采纳答案by micantox
If the elements of the view are the same (and only the actual text and images are changing), all you need to do in your storyboard is to create one view controller that will have all these ui elements, from code you can then set it up depending on the content that you want to display in it (depending on what the user clicked in the previous view controller).
如果视图的元素相同(并且只有实际的文本和图像发生了变化),您需要在故事板中做的就是创建一个视图控制器,该控制器将包含所有这些 ui 元素,然后您可以从代码中设置它up 取决于您要在其中显示的内容(取决于用户在前一个视图控制器中单击的内容)。
EDIT:
Not sure why it was downvoted, but i'll be more clear. Clearly that one view controller is not ALL you need to do in the storyboard. It's all you need to do ON the storyboard related to all the elements called Page in the diagram. Then you would have to link it to a PageViewController class and to all the outlets related to configurable UI elements and in the code of your prepareForSegue:
method from the Secondary Nav Screen View Controller
?you would have to configure it accordingly to what you want to show.
编辑:不知道为什么它被否决了,但我会更清楚。很明显,一个视图控制器并不是你在故事板中需要做的全部。这就是您需要在与图中所有名为 Page 的元素相关的情节提要上执行的操作。然后,您必须将其链接到 PageViewController 类以及与可配置 UI 元素相关的所有出口,以及您的prepareForSegue:
方法代码中的Secondary Nav Screen View Controller
? 您必须根据要显示的内容对其进行相应配置。
Hereyou can find a good beginner's tutorial, along with many other good tutorials. What you're probably missing is that you also need to tell the storyboard what class the view controller is and how to connect stuff like labels and imageviews to the actual code so that you can configure them appropriately.
在这里您可以找到一个很好的初学者教程,以及许多其他好的教程。您可能缺少的是,您还需要告诉情节提要视图控制器是什么类以及如何将标签和图像视图等内容连接到实际代码,以便您可以适当地配置它们。
I.E.
IE
回答by Simon
From what you're describing, it sounds like you want a UINavigationController
as your app's window's rootViewController
and to show your screens inside that. You want to create four controller classes:
根据您的描述,听起来您想要一个UINavigationController
作为应用程序窗口的窗口rootViewController
并在其中显示您的屏幕。您要创建四个控制器类:
HMMainScreenController
HMSecondaryScreenController
HMListScreenController
HMPageController
HMMainScreenController
HMSecondaryScreenController
HMListScreenController
HMPageController
Hopefully it's obvious what would be in each. You'd set up your window in your app delegate like this:
希望每个中的内容都很明显。您可以像这样在应用程序委托中设置窗口:
HMMainScreenController *mainController = [[HMMainScreenController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
When the user taps a button in your main controller, you'd do this:
当用户点击主控制器中的按钮时,您将执行以下操作:
HMSecondaryScreenController *secondaryController = [[HMSecondaryScreenController alloc] init];
// configure it appropriately
[self.navigationController pushViewController:secondaryController];
and so on for your list and page controllers.
等等用于您的列表和页面控制器。