第一个 iPhone 多视图应用程序 - 一些指导

发布于 2024-10-19 21:47:53 字数 313 浏览 9 评论 0原文

我想制作一个具有 5-6 个不同屏幕和一个数据源来存储用户信息的多视图应用程序。我以前从未制作过多视图应用程序,并且我对如何开始有一个好主意,但我想听到一些有关“构建”应用程序以正确支持此功能的建议。

一个非常简单的类比可能是在网站上制作背景颜色......您可以使用纯色图像或简单地使用背景颜色样式。两者都可以完成工作,但使用该样式更容易/更高效。

我只是想确保我的起步是正确的。我应该将所有函数保留在一个类的 .m/.h 文件中吗?处理不同屏幕的最佳/有效方法是什么?

谢谢,一旦我更好地掌握了 Objective-C 和 Xcode,我一定会尽力帮助其他人。

I'm wanting to make a multiview app with 5-6 different screens and a data source to store user information. I've never made a multiview app before, and I have a good idea on how to start, but I'd like to hear some recommendations on "structuring" your app to properly support this.

A very simple analogy could be going about making a background color on a website... You could either use an image of a solid color or simply use the background-color style. Both get the job done, but using the style is a bit easier/more efficient.

I just want to make sure I'm starting off on the right foot. Should I keep all my functions in one class' .m/.h file? What's the best/efficient way to go about different screens?

Thanks, and I'll definitely try to help others out once I get a much better grasp on Objective-C and Xcode.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

简单气质女生网名 2024-10-26 21:47:53

如果您是 iPhone/iPad 新手,我强烈建议您查看 CS193P< /a> 讲座,它们也在 iTunes 上提供。他们很好地概述了 iPhone 编程以及如何在 Objective-C / Cocoa Touch 中完成工作。它将使任何人开始朝着正确的方向前进。

至于你的具体问题。开始编码吧。 6 个月后,你会意识到你写的所有东西都是 cr*p 并且无论如何都需要重写,但这样做是你意识到你写的东西是 cr*p 的唯一方法,所以......

一些建议,特定于多 -查看过的应用程序(几乎每个应用程序都是),我确信其他人可以对此进行扩展...

  1. 学习(尽可能多地)编写不同视图和视图控制器之间的交互代码(与使用界面生成器相比)。例如,twitter 应用程序根本不使用 Interface Builder。
  2. 如果您使用 IB,请勿将所有内容转储到一个 .xib 中。了解如何分解它们。每个视图控制器一个 .xib 应该就是这样。我从不使用 IB UITabBarController 或 IB UINavigationController,它们仅在代码中初始化和使用。
  3. 绝对学习MVC(模型视图控制器)。

If you are new to the iPhone/iPad I highly recommend you check out the CS193P lectures, they are also avaliale on itunes. They give a good overview of iPhone programing and how things are done in Objective-C / Cocoa Touch. It will get anyone started in the right direction.

As to your specific question. Just start coding. In 6 months you'll realize eveything you wrote is cr*p and needs to be rewritten anyways, but doing it is the only way you'll realize what you wrote is cr*p so...

Some suggestions, specific to multi-viewed apps (which almost every app is) and I'm sure someone else can expand on this...

  1. Learn (as much as possible) to code interactions between different views and viewcontrollers (vs using interface builder). The twitter app for example doesn't use Interface Builder at all.
  2. If you use IB, don't dump everything into one .xib. Learn how to break them up. One .xib per viewcontroller should be it. I never use the IB UITabBarController or IB UINavigationController, those get initilized and used in code only.
  3. Absolutly learn MVC (Model view controller).
可爱咩 2024-10-26 21:47:53

对于大多数事情来说,Apple 文档通常是一个很好的起点。尝试 这里首先。希望这有帮助,祝你好运!

The Apple documentation is often a good place to start for most things. Try here first. Hope this helps and good luck!

我为君王 2024-10-26 21:47:53

我曾经使用 UINavigationController。我将其创建为单例并静态访问它,以便我可以轻松地推送和弹出控制器(有一个相当好的教程 此处)。这是相当轻量级的,并且有足够的文档可以快速使用它。

然而,我使用过的最好方法是 Three20 框架的 TTNavigator。简而言之,它是一个增强的 UINavigator,可让您通过调用内部 URL 将新视图推送到屏幕上:

//(In your app delegate)
//Start up the navigator
TTNavigator* navigator = [TTNavigator navigator];
navigator.persistenceMode = TTNavigatorPersistenceModeTop;

//Map url's to controllers
TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]];
[map from:@"ac://search" toViewController:[SearchViewController class]];
[map from:@"ac://results/(initToView:)" toViewController:[ResultsViewController class]];

然后导航到控制器:

[[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:@"ac://results/searchResults/"] applyAnimated:YES]];

同样酷的是,以我们的方式调用 @"ac://results/"上面将参数 @"searchResults" 传递给 ResultsViewController 的 init 方法("initToView:"),正如我们在映射器中定义的那样 祝

一切顺利!

I used to use a UINavigationController. I created it as a singleton and accessed it statically so I could push and pop controllers easily (theres a reasonably good tutorial here). This is quite lightweight and theres enough documentation to get going with it quickly.

However the best approach I've used is the Three20 framework's TTNavigator. In a nutshell its a beefed up UINavigator that lets you push a new view onto the screen by calling an internal URL:

//(In your app delegate)
//Start up the navigator
TTNavigator* navigator = [TTNavigator navigator];
navigator.persistenceMode = TTNavigatorPersistenceModeTop;

//Map url's to controllers
TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]];
[map from:@"ac://search" toViewController:[SearchViewController class]];
[map from:@"ac://results/(initToView:)" toViewController:[ResultsViewController class]];

Then to navigate to a controller:

[[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:@"ac://results/searchResults/"] applyAnimated:YES]];

Whats also cool is that calling that @"ac://results/" the way we have above passes in the param @"searchResults" to the init method of the ResultsViewController ("initToView:") as we defined in the mapper

All the best!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文