view types - view常见类型

Align : 校准。创建校准限制,比如将一个view在他的容器中居中或者校准两个view的左边缘

Pin: 创建间距限制,比如定义一个view的高度或者指定他到另一个view的水平距离。

Resolve Auto Layout Issues: 通过添加或者重新设置建议限制来解决layout问题。

Resizing Behavior: 指明resizing如何作用于限制。

View Controllers

A view controller isn’t part of the view hierarchy, and it’s not an element in your interface. Instead, it manages the view objects in the hierarchy and provides them with behavior. Each content view hierarchy that you build in your storyboard needs a corresponding view controller, responsible for managing the interface elements and performing tasks in response to user interaction. This usually means writing a custom UIViewController subclass for each content view hierarchy. If your app has multiple content views, you use a different custom view controller class for each content view.

view controller不是view 层级关系中的一部分也不是你interface的一个元素。他管理层级关系中的view对象 and provides them with behavior.每一个你在storyboard中创建的content view都需要一个对应的view controller来负责管理interface元素和行为任务。这通常意味着为每一个content view层级来创建自定义的UIViewController子类。如果你的app有多个content view,你可以为每个content view创建不同的自定义view controller。

View controllers play many roles. They coordinate the flow of information between the app’s data model and the views that display that data, manage the life cycle of their content views, and handle orientation changes when the device is rotated. But perhaps their most obvious role is to respond to user input.

view controller扮演很多角色。他们协调app数据模型间的信息流程和展示数据的views。管理content view的生命周期并且当设备旋转时处理方向变动。但是或许他们最主要的作用是响应用户输入。

You also use view controllers to implement transitions from one type of content to another. Because iOS apps have a limited amount of space in which to display content, view controllers provide the infrastructure needed to remove the views of one view controller and replace them with the views of another.

你也使用view controller来执行从一个content到另一个content的传递。因为ios app有显示content的空间限制,view controller提供从一个view controller移除view并且使用其他view来替换的工作。

To define interaction in your app, you make your view controller files communicate with the views in your storyboard. You do this by defining connections between the storyboard and source code files through actions and outlets.

为了定义你的app中的交互,你另storyboard中的view controller files和views之间可以通信。你利用actions和outlets来定义storyboard和source code files之间的联系。

Navigation Controllers

If your app has more than one content view hierarchy, you need to be able to transition between them. For this, you’ll use a specialized type of view controller: a navigation controller (UINavigationController). A navigation controller manages transitions backward and forward through a series of view controllers, such as when a user navigates through email accounts, inbox messages, and individual emails in the iOS Mail app.

如果你有多个content view层,你需要能够在他们中间过渡。为了实现这个,你就会使用一种特定类型的view controller:一个navigation controller(UINavigationController).一个navigation controller管理在一系列view controllers之间向后和向前传递。

The set of view controllers managed by a particular navigation controller is called its navigation stack. The navigation stack is a last-in, first-out collection of custom view controller objects. The first item added to the stack becomes the root view controller and is never popped off the stack. Other view controllers can be pushed on or popped off the navigation stack.

被naviagation controller管理的一系列view controllers叫做他的navigation stack。导航栈。navigation stack是一个后进先出的自定义view controller 对象集合。第一个添加进去的item就成为了root view controller。并且永远不会popped off堆栈。其他的view controllers会被压入或者推出navigation stack。

Although a navigation controller’s primary job is to manage the presentation of your content view controllers, it’s also responsible for presenting custom views of its own. Specifically, it presents a navigation bar—the view at the top of the screen that provides context about the user’s place in the navigation hierarchy—which contains a back button and other buttons you can customize. Every view controller that’s added to the navigation stack presents this navigation bar. You are responsible for configuring the navigation bar.

尽管一个navigation controller的首要任务是管理你的content view controllers。他也负责自定义view的行为。特别是,他呈现一个naviagtion bar-在屏幕上方的一个view-包含一个back按钮和其他你自定义的按钮。每一个添加到navigation stack中的view controller都显示这个navigation bar。你负责配置navigation bar。

You generally don’t have to do any work to pop a view controller off of the navigation stack; the back button provided by the navigation controller handles this for you. However, you do have to manually push a view controller onto the stack. You can do this using storyboards.

你通常不需要为弹出一个view controller做任何事情。navigation controller提供的返回按钮负责这个。但是你需要手动push一个view controller进stack中,你可以利用storyboards来实现这个目的。

Working with Foundation

Value Objects

Some examples of value objects in the Foundation framework are:

  • NSString and NSMutableString

  • NSData and NSMutableData

  • NSDate

  • NSNumber

  • NSValue

Collection Objects

  • NSArray and NSMutableArray. An array is an ordered collection of objects. You access an object by specifying its position (that is, its index) in the array. The first element in an array is at index 0 (zero).

  • NSSet and NSMutableSet. A set stores an unordered collection of objects, with each object occurring only once. You generally access objects in the set by applying tests or filters to objects in the set.

  • NSDictionary and NSMutableDictionary. A dictionary stores its entries as key-value pairs; the key is a unique identifier, usually a string, and the value is the object you want to store. You access this object by specifying the key.

Arrays

Sets

A set (NSSet) object is similar to an array, but it maintains an unordered group of distinct objects.

Because sets don’t maintain order, they offer faster performance than arrays do when it comes to testing for membership.

Because the basic NSSet class is immutable, its contents must be specified at creation, using either an initializer or a class factory method.

  1. NSSet *simpleSet =
  2. [NSSet setWithObjects:@"Hello, World!", @42, aValue, anObject, nil];

As with NSArray, the initWithObjects: and setWithObjects: methods both take a nil-terminated, variable number of arguments. The name of the mutable NSSet subclass is NSMutableSet.

Sets store only one reference to an individual object, even if you try adding an object more than once.

  1. NSNumber *number = @42;
  2. NSSet *numberSet =
  3. [NSSet setWithObjects:number, number, number, number, nil];
  4. // numberSet only contains one object

Dictionaries

Tutorial: Add Data

创建一个自定义的类来显示有用的数据。

This tutorial teaches you how to:

  • Work with common Foundation classes     同一般的foundation类合作

  • Create custom data classes  创建自定义的data classes

  • Implement a data source and delegate protocol  执行一个data source和delegate protocol

  • Pass data between view controllers 在view controller之间传递数据

Create a Data Class

To create the ToDoItem class

  1. Choose File > New > File (or press Command-N).

    A dialog appears that prompts you to choose a template for your new file.

  2. On the left, select Source under iOS.

  3. Select Cocoa Touch Class, and click Next.

  4. In the Class field, type ToDoItem.

  5. Choose NSObject from the “Subclass of” pop-up menu. //继承自 NSObject 类

  6. Click Next.

    The save location defaults to your project directory.

    The Group option defaults to your app name, ToDoList.

    In the Targets section, your app is selected and the tests for your app are unselected.

  7. Leave these defaults as they are, and click Create.

To configure the ToDoItem class //配置todoitem类

  1. In the project navigator, select ToDoItem.h.

  2. Add the following properties to the interface so that the declaration looks like this:

    1. @interface ToDoItem : NSObject
    2. @property NSString *itemName;
    3. @property BOOL completed;
    4. @property (readonly) NSDate *creationDate;
    5. @end

    Load the Data //加载数据

    1. In the project navigator, select ToDoListTableViewController.m.

      Because the array of items is an implementation detail of your table view controller, you declare it in the .m file instead of the .h file. This makes it private to your custom class.

    2. Add the following property to the interface category Xcode created in your custom table view controller class. The declaration should look like this:

      1. @interface ToDoListTableViewController ()
      2. @property NSMutableArray *toDoItems;
      3. @end
    3. Find the viewDidLoad method. The template implementation looks like this:

      1. - (void)viewDidLoad {
      2. [super viewDidLoad];
      3. // Uncomment the following line to preserve selection between presentations.
      4. // self.clearsSelectionOnViewWillAppear = NO;
      5. // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
      6. // self.navigationItem.rightBarButtonItem = self.editButtonItem;
      7. }

      The template implementation of this method includes comments that were inserted by Xcode when it created ToDoListTableViewController. Code comments like this provide helpful hints and contextual information in source code files, but you don’t need them for this tutorial. Feel free to delete the comments.

    4. Update the method implementation to allocate and initialize the toDoItems array in the viewDidLoad method:

      1. - (void)viewDidLoad {
      2. [super viewDidLoad];
      3. self.toDoItems = [[NSMutableArray alloc] init];
      4. }

Start Developing iOS Apps Today的更多相关文章

  1. 《Start Developing iOS Apps Today》摘抄

    原文:<Start Developing iOS Apps Today> Review the Source Code 入口函数main.m #import <UIKit/UIKit ...

  2. iOS Start developing ios apps (OC) pdf

    这是苹果官方最后一次更新的基于OC的iOS开发基础教程, 如果英文的看不懂,还有中文的版本哦. 点击下面的链接 好东西,分享给大家! 如果确实有帮到你,麻烦star一下我的github吧!

  3. 官方文档学习之《start developing iOS apps(swift)》

    1.  let 关键字是用来定义常量的,任何类型的常量都可以进行定义:例如:定义字符串 let constantValue1 = "this is a string",也可以定义数 ...

  4. Start Developing iOS Apps (Swift) 开始开发iOS应用(Swift)

    http://www.cnblogs.com/tianjian/category/704953.html 构建基础的用户界面 Build a Basic UI http://www.cnblogs.c ...

  5. Table View Programming Guide for iOS---(一)---About Table Views in iOS Apps

    About Table Views in iOS Apps Table views are versatile user interface objects frequently found in i ...

  6. Developing iOS8 Apps with Swift——iOS8概览

    iOS 8 概览 斯坦福公开课--Developing iOS8 Apps with Swift学习笔记 想学习Swift,但是相应的教程不是很多,在CoCoaChina社区闲逛时恰好发现了这门课程, ...

  7. Adding AirDrop File Sharing Feature to Your iOS Apps

    http://www.appcoda.com/ios7-airdrop-programming-tutorial/ Adding AirDrop File Sharing Feature to You ...

  8. ComponentOne Xuni助力Xamarin开发者突破百万,快速开发Android、IOS Apps

    在微软Build 2015上,随着VS 2015的预览版发布,Xamrine免费版已经作为VS 2015跨平台移动解决方案的核心.与此同时,Xamarin官方也宣布其用户量达到百万之多.2011年7月 ...

  9. Differences Between Xcode Project Templates for iOS Apps

    Differences Between Xcode Project Templates for iOS Apps When you create a new iOS app project in Xc ...

随机推荐

  1. Hyper-V:利用差异磁盘安装多个Win2008

    签于成本的原因,在学习了解一项新的技术或是产品时,在没有部署到生产环境之中前,大家都会选择在虚拟机来搭建一套实验环境.但如何快速搭建呢?如何节省磁盘空间呢? 说到此都不得不说下Hyper-V的差异磁盘 ...

  2. c++树及树与二叉树的转换

    此算法中的树结构为“左儿子有兄弟链接结构” 在这样的一个二叉树中,一个节点的左分支是他的大儿子节点,右分支为他的大兄弟节点. 这里讲的树有递归前根,中根,后根遍历,插入节点,插入兄弟节点,查找结点,释 ...

  3. sed处理大txt文件(1G) 比如替换某一串字符串,或者删除一行

    1.将11.sql文件中"prompt"替换为"--prompt",然后保存为111.sql文件 sed -e "s,prompt,--prompt, ...

  4. pip更新产生的问题及其解决方法?

    运行 pip3 install --upgrade pip 发生错误: from pip import main ImportError: cannot import name 'main' 将以下代 ...

  5. 【转】网页游戏能用PHP做后端开发吗? PHP Libevent扩展安装及应用

    网页游戏能用PHP做后端开发吗? 当然可以.最好走HTTP,也可以做网络编程,而且写代码超简单,1个函数就可以建一个服务器端.stream_socket_server()多线程不是什么好主意,你可以用 ...

  6. VS 2013插件

    http://www.spersky.com/post/vsPlugins.html http://vswebessentials.com/download http://developer.51ct ...

  7. 【bzoj2721】[Violet 5]樱花 数论

    题目描述 输入 输出 样例输入 2 样例输出 3 题解 数论 设1/x+1/y=1/m,那么xm+ym=xy,所以xy-xm-ym+m^2=m^2,所以(x-m)(y-m)=m^2. 所以解的数量就是 ...

  8. nginx通过spawn-fcgi调用C++写的cgi程序

    通过apt-get install 安装nginx和spawn-fcgi /usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 9002 -C 25 -f  ...

  9. [TC_SRM_466]DrawingBlackCrosses

    [TC_SRM_466]DrawingBlackCrosses 试题描述 \(n \times m\)(\(n, m \le 20\))的棋盘 其中至多有 \(8\) 个格子为黑色,其他格子为白色 每 ...

  10. a:active在ios上无效解决方法

    原因: By default, Safari Mobile does not use the :active state unless there is a touchstart event hand ...