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. 编程高手解读什么是NodeJs?

    首先在搞清楚什么NodeJs之前,我们先来聊聊JavaScript,只要做过开发的人都应该知道JavaScript是目前最为流行的前端(客户端)脚 本语言,JavaScript在Web项目中的使用率可 ...

  2. 【清华集训】小Y和地铁

    图已挂,前往luogu 题目: 小 $\rm Y$ 是一个爱好旅行的 $\rm OIer$.一天,她来到了一个新的城市.由于不熟悉那里的交通系统,她选择了坐地铁.她发现每条地铁线路可以看成平面上的一条 ...

  3. 第九届极客大挑战 部分WP

    CODE 和0xpoker分0day 百度 取石子游戏. https://blog.csdn.net/qq_33765907/article/details/51174524 已经说得很详细了,慢慢来 ...

  4. 【Python Selenium】简单数据生成脚本

    最近因工作需要,写了一个简单的自动化脚本,纯属学习,顺便学习下selenium模块. 废话不多说,直接上代码!! 这里一位大神重写了元素定位.send_keys等方法,咱们直接进行调用. 适用Pyth ...

  5. Selenium中如何运行 auto.exe 文件

    Runtime exe = Runtime.getRuntime(); try{ String str = "D:\\Auto上传文件\\photo.exe"; exe.exec( ...

  6. Leetcode 611.有效三角形的个数

    有效三角形的个数 给定一个包含非负整数的数组,你的任务是统计其中可以组成三角形三条边的三元组个数. 示例 1: 输入: [2,2,3,4] 输出: 3 解释: 有效的组合是: 2,3,4 (使用第一个 ...

  7. python 模块初识

    python的强大之处在于有丰富的实现各种功能的标准库和第三方库,另外还允许用户自己建立库文件, 标准模块(又称为库)包括sys, os, glob, socket, threading, _thre ...

  8. Groovy安装

    进入Groovy的官网下载安装SDKMAN() 以下是官网的下载方法(http://www.groovy-lang.org/download.html) This tool makes install ...

  9. IPFS

    http://www.r9it.com/20190412/ipfs-private-net.html IPFS指令集中文版(一) https://www.jianshu.com/p/ce74b32d2 ...

  10. jupyter的使用

    shift+enter 运行程序 Tab 代码补全 shift+Tab 查看函数说明 shift+Tab+Tab 查看函数详细说明 https://www.dataquest.io/blog/jupy ...