简体   繁体   English

iPhone开发 - 应用程序设计模式

[英]iPhone development - app design patterns

There are tons of resources concerning coding on the iPhone. 关于iPhone的编码有大量资源。 Most of them concern "how do I do X", eg "setup a navigation controller", or "download text from a URL". 其中大多数涉及“我如何做X”,例如“设置导航控制器”或“从URL下载文本”。 All good and fine. 一切都好又好。

What I'm more interested in now are the questions that follow the simpler stuff - how to best structure your complex UI, or your app, or the common problems that arise. 我现在更感兴趣的是更简单的问题 - 如何最好地构建复杂的用户界面或应用程序,或出现的常见问题。 To illustrate: a book like "Beginning iPhone 3 Development" tells you how to set up a multi viewcontroller app with an top 'switcher' viewcontroller that switches between views owned by other view controllers. 为了说明:像“开始iPhone 3开发”这样的书告诉你如何设置一个多视图控制器应用程序,其顶部的“切换器”视图控制器可以在其他视图控制器拥有的视图之间切换。 Fine, but you're only told how to do that, and nothing about the problems that can follow: for example, if I use their paradigm to switch to a UINavigationViewController, the Navigation bar ends up too low on the screen, because UINavigationViewController expects to be the topmost UIViewController (apparently). 很好,但你只被告知如何做到这一点,而不是可能出现的问题:例如,如果我使用他们的范例切换到UINavigationViewController,导航栏在屏幕上的结果太低,因为UINavigationViewController期望成为最顶级的UIViewController(显然)。 Also, delegate methods (eg relating to orientation changes) go to the top switcher view controller, not the actual controller responsible for the current view. 此外,委托方法(例如与方向改变有关)转到顶部切换器视图控制器,而不是负责当前视图的实际控制器。 I have fixes for these things but they feel like hacks which makes me unhappy and makes me feel like I'm missing something. 我已经修复了这些东西,但他们感觉像黑客让我不开心,让我觉得我错过了什么。

One productive thing might be to look at some open source iPhone projects (see this question ). 一个有成效的事情可能是看一些开源的iPhone项目(见这个问题 )。 But aside from that? 但除此之外呢?

Update 更新

To clarify: I suppose what I'm asking about could be summarised as "Recipes and Gotchas for iPhone development". 澄清:我想我所问的可以概括为“iPhone开发的食谱和陷阱”。 The sort of things that are of interest to developers, but aren't covered in any of the iPhone books etc. that I've seen, such as: 开发人员感兴趣的东西,但我见过的任何iPhone书籍都没有涉及,例如:

  • I'm writing an iPad app and want a UISplitViewController presented to the user only some of the time, which Apple seem to be saying I can't do. 我正在编写一个iPad应用程序,并希望在某些时候只向用户呈现一个UISplitViewController,Apple似乎在说我做不到。 Is it possible? 可能吗? How? 怎么样?

  • Apple don't give me a way to stylise my app in a convenient, across the board way (eg font tweaks, or colours). Apple没有给我一种方便,全面的方式来设计我的应用程序的方式(例如字体调整或颜色)。 How can I approach styling my app? 如何处理我的应用程序样式?

  • Memory management isn't made any easier by some of the inconsistencies in UIViewController method names (eg viewDidUnload is not the opposite of viewDidLoad, despite the name). UIViewController方法名称中的一些不一致性使内存管理变得更容易(例如,尽管名称,viewDidUnload与viewDidLoad 相反)。 Is there a consistent easy way to tidy that up and make view controller memory management less error prone? 是否有一致的简单方法来整理它并使视图控制器内存管理不易出错?

  • How can I consistently and easily test my view controllers for behaving correctly when a memory warning comes in? 当内存警告进入时,如何能够始终如一地轻松测试我的视图控制器是否正常运行? It's easy to simulate a memory warning in the Simulator, but if the UI I want to test is showing (and is a 'leaf level' view controller), it won't get its view unloaded because it is currently visible. 在模拟器中模拟内存警告很容易,但如果我要测试的UI正在显示(并且是一个“叶级”视图控制器),它将不会卸载其视图,因为它当前是可见的。

NB I'm not actually asking the above questions here -- I think I have decent answers to them! NB我实际上并没有在这里提出上述问题 - 我想我对他们有很好的答案! -- just giving examples of 'good' questions that illustrate this stackoverflow question. - 仅举出说明此stackoverflow问题的“好”问题示例。

The WWDC talks available on iTunes U (at http://developer.apple.com/videos/wwdc/2010/ ) have some great information about structuring, especially in the Application Frameworks section. iTunes U上的WWDC会谈( http://developer.apple.com/videos/wwdc/2010/ )提供了一些有关结构化的重要信息,尤其是在“应用程序框架”部分。

If you're talking about code, use the Model/View/Controller pattern like in most Web applications: 如果您正在谈论代码,请使用大多数Web应用程序中的模型/视图/控制器模式:

  • The model code defines the objects that your program represents. 模型代码定义程序表示的对象。 A time tracker app, for example, might have model objects like Task, TimeSlice, and User (especially in a network setting). 例如,时间跟踪器应用程序可能具有Task,TimeSlice和User等模型对象(特别是在网络设置中)。
  • The view code is provided for "free" with the iOS SDK, unless you need specialised view code. 除非您需要专门的视图代码,否则视图代码是使用iOS SDK“免费”提供的。 These are UIImageView, UIButton, etc. 这些是UIImageView,UIButton等。
  • The controller code bridges the 'gap' between the model and view. 控制器代码桥接模型和视图之间的“间隙”。 The controller will change the views to reflect the model selected by the user and facilitate the selection of model objects. 控制器将更改视图以反映用户选择的模型,并便于选择模型对象。

This is the base design pattern for any iPhone app, and it's the one that most will use. 这是任何iPhone应用程序的基本设计模式,也是最常用的应用程序模式。

If, on the other hand, you refer to what we in my company call UX (user experience) design, however, you can't beat the Apple HIG guidelines in the Apple iOS SDK documentation set, available online or in Xcode from the Help menu. 另一方面,如果你指的是我们公司所谓的UX(用户体验)设计,那么你无法在Apple iOS SDK文档集中击败Apple HIG指南,可以在线获得,也可以从帮助中的Xcode中获取菜单。

The other thing I recommend quite highly is to play around with some test/dummy code. 我推荐的另一件事就是玩一些测试/虚拟代码。 Nothing can top experience. 没有什么可以顶级体验。 Experimenting with the iOS SDK and getting your hands dirty will allow you to truly learn the best ways to design apps. 尝试使用iOS SDK并亲自动手,可以让您真正了解设计应用程序的最佳方法。

Edit: 编辑:

Also, delegate methods (eg relating to orientation changes) go to the top switcher view controller, not the actual controller responsible for the current view. 此外,委托方法(例如与方向改变有关)转到顶部切换器视图控制器,而不是负责当前视图的实际控制器。

Can you clarify? 你能澄清一下吗? In all of the apps I've written, the currently shown view controller receives the orientation change methods. 在我编写的所有应用程序中,当前显示的视图控制器接收方向更改方法。 Note that there are two methods. 请注意,有两种方法。 shouldAutorotateToInterfaceOrientation: allows you to decide if the view should rotate, and didRotateFromInterfaceOrientation: allows you to re-layout the view if necessary. shouldAutorotateToInterfaceOrientation:允许您决定视图是否应该旋转,并且didRotateFromInterfaceOrientation:允许您在必要时重新布局视图。

Please go through this link. 请仔细阅读此链接。 In this they have explained clearly about design patterns. 在这方面,他们已经清楚地解释了设计模式。

http://www.raywenderlich.com/46988/ios-design-patterns http://www.raywenderlich.com/46988/ios-design-patterns

您可能需要考虑在iTunes U上观看来自Stanford的CS193p课程等视频。他们深入研究了iOS开发中最重要的部分,并提供了一些源代码。

As far as I can tell, there isn't a book or resource which deals with the sort of advanced gotchas and recipes that I was looking for. 据我所知,没有一本书或资源可以处理我正在寻找的那种先进的陷阱和食谱。 Loads of useful resources exist, but just not addressing the stuff I'm thinking about. 存在大量有用的资源,但只是没有解决我正在考虑的问题。

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

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