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. tomcat内存泄漏存入dump文件

    很多tomcat进程退出(或者进程假死),都是由于频繁的抛出OutOfMemeoryError导致的. 为了让tomcat退出前或者发生OutOfMemeoryError时自动dump堆栈信息,方便事 ...

  2. 【Reverse Integer】cpp

    题目: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click ...

  3. Python+Selenium练习篇之10-刷新当前页面

    本文介绍如何调用webdriver中刷新页面的方法. 相关脚本代码如下: # coding=utf-8import timefrom selenium import webdriver driver ...

  4. 【转】Unity5.x发布IOS项目Xcode8免签证调试发布教程

    http://www.jianshu.com/p/b0fb49fbcc14 最近尝试发布一下IOS项目,发现现在发布已经简单很多了,不需要开发者账户也能简单快捷进行真机调试. 调试: 1.准备工作①硬 ...

  5. Nodejs项目网页图标的处理

    今天,我要说的是Nodejs中,关于网页图标的处理. 在讲解怎么处理之前,我们的了解一下什么是网页图标.网页图标就是我们网页打开之后,标签页的图标,比如下面这个 前面的小人就是我们博客园的网页图标. ...

  6. 核苷酸(evolution)

    核苷酸(evolution) 题目描述 生物课是帕特里克最讨厌的课程,没有之一. 相比做一些无聊而又无趣的遗传题,他更喜欢其他所有的科目. 包括英语. 但是今天不同.他被一个关于RNA感染DNA的题目 ...

  7. String 类详解

    StringBuilder与StringBuffer的功能基本相同,不同之处在于StringBuilder是非线程安全的,而StringBuffer是线程安全的,因此效率上StringBuilder类 ...

  8. 小M的作物 最大权闭合子图

    题目大意 bzoj 3438 两个田\(A,B\) \(n\le 1000\)种作物的种子 第\(i\)个种子,种\(A\)价值\(a[i]\),种\(B\)价值\(b[i]\) 再给出\(m\)个子 ...

  9. NOI2001食物链

    描述 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A吃B,B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种. 有人 ...

  10. [LeetCode] Longest Substring Without Repeating Characters最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...