Start Developing iOS Apps Today
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
andNSMutableString
NSData
andNSMutableData
NSDate
NSNumber
NSValue
Collection Objects
NSArray
andNSMutableArray
. 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
andNSMutableSet
. 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
andNSMutableDictionary
. 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.
NSSet *simpleSet =
[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.
NSNumber *number = @42;
NSSet *numberSet =
[NSSet setWithObjects:number, number, number, number, nil];
// 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
Choose File > New > File (or press Command-N).
A dialog appears that prompts you to choose a template for your new file.
On the left, select Source under iOS.
Select Cocoa Touch Class, and click Next.
In the Class field, type
ToDoItem
.Choose NSObject from the “Subclass of” pop-up menu. //继承自 NSObject 类
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.
Leave these defaults as they are, and click Create.
To configure the ToDoItem class //配置todoitem类
In the project navigator, select
ToDoItem.h
.Add the following properties to the interface so that the declaration looks like this:
@interface ToDoItem : NSObject
@property NSString *itemName;
@property BOOL completed;
@property (readonly) NSDate *creationDate;
@end
Load the Data //加载数据
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.Add the following property to the interface category Xcode created in your custom table view controller class. The declaration should look like this:
@interface ToDoListTableViewController ()
@property NSMutableArray *toDoItems;
@end
Find the
viewDidLoad
method. The template implementation looks like this:- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
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.Update the method implementation to allocate and initialize the
toDoItems
array in theviewDidLoad
method:- (void)viewDidLoad {
[super viewDidLoad];
self.toDoItems = [[NSMutableArray alloc] init];
}
Start Developing iOS Apps Today的更多相关文章
- 《Start Developing iOS Apps Today》摘抄
原文:<Start Developing iOS Apps Today> Review the Source Code 入口函数main.m #import <UIKit/UIKit ...
- iOS Start developing ios apps (OC) pdf
这是苹果官方最后一次更新的基于OC的iOS开发基础教程, 如果英文的看不懂,还有中文的版本哦. 点击下面的链接 好东西,分享给大家! 如果确实有帮到你,麻烦star一下我的github吧!
- 官方文档学习之《start developing iOS apps(swift)》
1. let 关键字是用来定义常量的,任何类型的常量都可以进行定义:例如:定义字符串 let constantValue1 = "this is a string",也可以定义数 ...
- Start Developing iOS Apps (Swift) 开始开发iOS应用(Swift)
http://www.cnblogs.com/tianjian/category/704953.html 构建基础的用户界面 Build a Basic UI http://www.cnblogs.c ...
- 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 ...
- Developing iOS8 Apps with Swift——iOS8概览
iOS 8 概览 斯坦福公开课--Developing iOS8 Apps with Swift学习笔记 想学习Swift,但是相应的教程不是很多,在CoCoaChina社区闲逛时恰好发现了这门课程, ...
- Adding AirDrop File Sharing Feature to Your iOS Apps
http://www.appcoda.com/ios7-airdrop-programming-tutorial/ Adding AirDrop File Sharing Feature to You ...
- ComponentOne Xuni助力Xamarin开发者突破百万,快速开发Android、IOS Apps
在微软Build 2015上,随着VS 2015的预览版发布,Xamrine免费版已经作为VS 2015跨平台移动解决方案的核心.与此同时,Xamarin官方也宣布其用户量达到百万之多.2011年7月 ...
- 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 ...
随机推荐
- unknow table alarmtemp error when drop database (mysql)
Q: unknow table alarmtemp error when drop database (mysql) D: alarmtemp is table in rtmd database. ...
- Leetcode 558.四叉树交集
四叉树交集 四叉树是一种树数据,其中每个结点恰好有四个子结点:topLeft.topRight.bottomLeft 和 bottomRight.四叉树通常被用来划分一个二维空间,递归地将其细分为四个 ...
- c++ primer 读书笔记
顺序容器:为程序提供控制元素存储和访问顺序的能力,这种顺序与元素加入到容器时的位置相对应,而与元素值无关. 另外还有根据关键字的值来存储元素的容器:有序.无序关联容器. 另外STL还有三种容器适配器, ...
- [译]为什么pandas有些命令用括号结尾,有些则没有?
文章来源:https://nbviewer.jupyter.org/github/justmarkham/pandas-videos/blob/master/pandas.ipynb 方法:用括号调用 ...
- Javascript 表达式和运算符
属性访问表达式: var o = {x:1, y:{z:3}};//示例对象 var a = [o, 4, [5,6]];//包含对象的数组 console.log(o["x"]) ...
- 基于 <tx> 和 <aop> 命名空间的声明式事务管理
环境配置 项目使用SSH架构,现在要添加Spring事务管理功能,针对当前环境,只需要添加Spring 2.0 AOP类库即可.添加方法: 点击项目右键->Build Path->Add ...
- POJ 2184:Cow Exhibition(01背包变形)
题意:有n个奶牛,每个奶牛有一个smart值和一个fun值,可能为正也可能为负,要求选出n只奶牛使他们smart值的和s与fun值得和f都非负,且s+f值要求最大. 分析: 一道很好的背包DP题,我们 ...
- NetScaler通过DHCP服务器获取IP地址
NetScaler通过DHCP服务器获取IP地址 DHCP 选项参考 https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp ...
- 【bzoj3585】mex 线段树 mex,sg
Description 有一个长度为n的数组{a1,a2,…,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. Input 第一行n,m. 第二行为n个数. 从第三行开始,每行一个询问l, ...
- 四则运算出题系统,java
程序设计思想: 首先通过判断选择计算的范围,然后用随机数生成两个随机数,定义另一个数,将两个随机数计算得到的值赋给定义的数 程序代码: package Kaos1; import java.util. ...