简体   繁体   English

一起开发iPhone和iPad应用程序时的最佳做法是什么?

[英]What is the best practices when developing iphone and ipad app together?

I'm gonna create an app that supports both iPhone & iPad. 我要创建一个同时支持iPhone和iPad的应用程序。 Before proceeding, I just want to know the best practices about both app development. 在继续之前,我只想了解有关两个应用程序开发的最佳实践。

Here is some points that I know: 我知道以下几点:

  • Consider that I have a tableview that shows N number of records and say it as PAGE-1. 考虑一下我有一个显示N条记录的表视图,并将其表示为PAGE-1。 When the user tapping on the cell, it will load the PAGE-2 to show details about the tapped record. 当用户点击单元格时,它将加载PAGE-2以显示有关所点击记录的详细信息。 This is more common scenario that used in every app. 这是每个应用程序中使用的更常见的方案。
  • For iPad, this is not the case. 对于iPad,情况并非如此。 I can show PAGE-1 along with PAGE-2 in the same page.(Consider landscape mode) 我可以在同一页面上显示PAGE-1和PAGE-2。(考虑横向模式)
  • So, iPhone's PAGE-1 will be displayed in the left panel of the iPad & iPhone's PAGE-2 will be displayed in the right side panel of the iPad. 因此,iPhone的PAGE-1将显示在iPad的左侧面板中,而iPhone的PAGE-2将显示在iPad的右侧面板中。

Conclusion: 结论:

  • So, I can make a common class for both iPhone & iPad. 因此,我可以为iPhone和iPad设置一个通用类。 That will handle the PAGE-1's common functionality to both iPhone & iPad. 这将处理PAGE-1对iPhone和iPad的通用功能。
  • The device specific functionality may separated into separate classes for both iPhone and iPad. 特定于设备的功能可以分为iPhone和iPad的不同类。
  • Other than that, network related methods, parsers, utility methods, categories, custom controllers can be written commonly for both iPhone & iPad. 除此之外,可以为iPhone和iPad共同编写与网络相关的方法,解析器,实用程序方法,类别,自定义控制器。
  • The only addon to the iPad is, it should have a controller that will hold and handle PAGE-1 and PAGE-2. iPad唯一的附加组件是,它应该具有一个控制器,该控制器可以容纳并处理PAGE-1和PAGE-2。 This make sures that the PAGE-1 does not hold PAGE-2 and they both are independent like iPhone's PAGE-1 & PAGE-2. 这样可以确保PAGE-1不保存PAGE-2,并且它们都像iPhone的PAGE-1和PAGE-2一样独立。

Refer the below attached image that will demonstrate clearly. 请参考下面所附的图像,该图像将清晰显示。

在此处输入图片说明

Questions: 问题:

  • Is this approach correct? 这种方法正确吗?
  • I really don't know about iPad's "Container" controller. 我真的不知道iPad的“容器”控制器。 Should I need it? 我需要吗? Or is there any other better proposal to group the things effectively? 还是有其他更好的建议可以有效地对事物进行分组?

This may be a basic question, but I need a clarification for better code pratice. 这可能是一个基本的问题,但是我需要澄清以取得更好的代码实用性。

Thanks 谢谢

It doesn't sound like you need specific page 1 & 2 subclasses, though that depends on exactly what the differences are between the pages on each device. 听起来好像不需要特定的第1页和第2页子类,尽管这完全取决于每个设备上的页面之间的区别。 It may be that a collection view suits your needs better so you can simply set the item width and the layout will organise your content into columns where appropriate. 集合视图可能更适合您的需求,因此您可以简单地设置项目宽度,并且布局会将内容适当地组织为列。

It sounds more like all you need is 2 different container classes for the top level which decides how to display page(s), or more specifically, how many pages to display and where they are on screen. 听起来更像是您需要的是顶层的2个不同的容器类,这些类决定了如何显示页面,或更具体地说,决定了要显示多少页面以及它们在屏幕上的位置。 For iPhone that's really simple, for iPad slightly more complex (mainly due to rotation handling). 对于iPhone来说,这确实很简单,对于iPad,则稍微复杂一些(主要是由于旋转处理)。

Note also that if you create a new master-detail project in Xcode and ask it to support iPhone and iPad you will see that a split view controller is used, optionally, for exactly this situation. 还要注意,如果您在Xcode中创建一个新的主从项目,并要求它支持iPhone和iPad,您将看到针对这种情况(可选)使用了拆分视图控制器。 This bypasses the need for 2 container classes by having the app delegate decide whether to use a 'special' container or not (for iPad). 通过让应用程序委托决定是否使用“特殊”容器(对于iPad),从而无需2个容器类。

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

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