1. UITextView

@property(nonatomic,readonly,retain) NSTextStorage *textStorage

是 NSMutableAttributedString 的子类

[self.body.textStorage addAttributes:@{ NSStrokeWidthAttributeName : @-3,

NSStrokeColorAttributeName : [UIColor blackColor]}

range:self.body.selectedRange];

这里的 NSStrokeWidthAttributeName 的 -3 和 3 的区别是:

0表示无描边,正数表示描边,负数表示描边+填充;

假设原文字是(foreground color)蓝色的,用加了正数属性后,就仅有描边,成为空心轮廓的样式

2. View Controller Lifecycle(视图控制器生命周期)

所谓的视图控制器生命周期,其实就是一系列的方法,当事件发生时,会被发送至 UIViewController。如果需要重写这些方法,记得先super,例如:[super viewDidLoad];

解释下super:

向super发送消息时,系统在查找方法时会跳过当前对象的类,从父类开始查询,相当于是先调用了父类的同名方法。

viewDidLoad

- (void)viewDidLoad

适合放置视图控制器的初始化代码,一个生命周期中只会调用一次;

输出口(Outlet)已经设置好,故可以设置各种UI的初始化展示;

有一类操作不适合添加:关于视图几何的代码,因为在 viewDidLoad 被调用时,视图的边界(bounds)还没有定下来,它可能不会出现在预定位置,屏幕可能旋转之类的;总之,关于视图的大小、位置(统称几何)的代码不适合放在 viewDidLoad 中;

viewWillAppear

- (void)viewWillAppear:(BOOL)animated

每次视图重新在屏幕上显示时,viewWillAppear 就会被调用;

此时视图的几何信息已经设置,在这里可以执行一些基于几何的初始化;

viewWillDisappear

- (void)viewWillDisappear:(BOOL)animated

当视图从屏幕离开时,viewWillDisappear会被调用;

可以做些记住当前状态或保存数据的操作,以便重新回到视图时恢复;

viewDidAppear

- (void)viewDidAppear:(BOOL)animated

viewDidDisappear

- (void)viewDidDisappear:(BOOL)animated

viewWillLayoutSubviews

- (void)viewWillLayoutSubviews

当视图的frame变化,子视图重现布局时被调用,比如:屏幕旋转;

viewDidLayoutSubviews

- (void)viewDidLayoutSubviews

Between "will" and "did", autolayout will happen;

didReceiveMemoryWarning

- (void)didReceiveMemoryWarning

系统内存不足时会发送这个消息;

收到这个警告时,需要释放内存,也就是释放堆中的内容,也就是将强指针设为nil;

- (void)setup{ };

- (void)awakeFromNib{

[self setup];

}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

[self setup];

return self;

}

3. NSNotification

The “radio station” from the MVC slides.

radio station 包括了收听(tune into)消息和广播(broadcast)消息两块,本节只介绍收听的;

收听里面又分了收听系统消息和收听自定义的来自模型的消息,本节只介绍收听系统消息;

每一个iOS应用中都有一个 NSNotificationCenter 对象,对象可以将自己注册为某个通知的观察者(observer),例如:“如果有人找到了我丢失的

CS193p Lecture 5 - View Controller Lifecycle的更多相关文章

  1. iOS 因为reason: 'Pushing the same view controller instance more than once is not supported而奔溃(下)

    这个问题是什么意思呢,之前遇到过几次,但程序再次打开时没有问题,也就没有重视,今天又遇到了,无法忍受啊. 控制台报的错误是:"不支持多次推入相同的视图控制器实例". 什么原因造成的 ...

  2. 报错:Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard' - perhaps the designated entry point is not set?

    原因分析:在StoryBoard中没有一个view controller设置了Initial Scene. 解决方案:在Storyboard中,选择一个view conroller作为story bo ...

  3. iOS架构师之路:控制器(View Controller)瘦身设计

    前言 古老的MVC架构是容易被iOS开发者理解和接受的设计模式,但是由于iOS开发的项目功能越来越负责庞大,项目代码也随之不断壮大,MVC的模糊定义导致我们的业务开发工程师很容易把大量的代码写到视图控 ...

  4. View Controller Relationships

    Parent-child relationshipsParent-child relationships are formed when using view controller container ...

  5. Model View Controller

    On the iPhone or iPod touch, a modal view controller takes over the entire screen. This is the defau ...

  6. UISearchController Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior

    Attempting to load the view of a view controller while it is deallocating is not allowed and may res ...

  7. Application tried to present a nil modal view controller on target “Current View Controller”解决方案

    情景再现 1,自定义一个storyboard: 打开xcode,按下cmd+N,新建一个Storyboard--->next 将新建立的storyboard命名为:TestViewControl ...

  8. 【IOS笔记】View Controller Basics

    View Controller Basics   视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...

  9. UIStoryboard类介绍(如何从Storyboard中加载View Controller)

    如何从Storyboard中加载View Controller? 1. 首先了解下UIStoryboard类: @class UIViewController; @interface UIStoryb ...

随机推荐

  1. laravel 路由设置

    目录  routes\web.php 初始路由,直接渲染视图welcome,即V层   '/'为路径:www.xxx.com/ Route::get('/', function () { return ...

  2. BAT或赌在当下或押在未来,谁是王者?

    转自:http://www.tmtpost.com/97132.html 百度阿里和腾讯三家本来的核心业务并不冲突,各守一方阵地,但随着各自的收购注资加上业务的延展而慢慢有了交际,阿里和腾讯在移动支付 ...

  3. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:9. 自定义委托事件方法

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  4. 分布式通信-tcp/ip 单播

    服务端 public class SingleBroadCastSocketServer { public static void main(String[] args) { ServerSocket ...

  5. Connected Components? Codeforces - 920E || 洛谷 P3452 &&bzoj1098 [POI2007]BIU-Offices

    https://codeforces.com/contest/920/problem/E https://www.luogu.org/problemnew/show/P3452 https://www ...

  6. 面向对象多继承(C3算法)/网络编程

    https://www.cnblogs.com/aylin/p/5572104.html 一.面向对象多继承(c3算法) a.有多个父类先找左,再找右,如下示例: class A(object): p ...

  7. E. The Best among Equals

    http://codeforces.com/gym/101149/problem/E 这题的话,关键是注意到一定是要max score 然后就可以选出一个L最大优先,并且R最大的区间, 扫一次就能得到 ...

  8. ecshop文章分类页面调用文章的内容

    有的时候需要用到,所以总结了一下. 打开includes/lib_article.php文件 红色部分为添加的部分 function get_cat_articles($cat_id, $page = ...

  9. unix&linux常用命令分类表

    本附录([美]哈恩:<Unix&Linux大学教程>附录B,张杰良译,清华大学出版社,2010年)摘要描述了书中所涉及的143个Unix使命,并且按照命令的类别进行排列.在每个名称 ...

  10. 设置Eclipse可以Debug模式调试JDK源码,并显示局部变量的值

    最近突然萌发了研究JDK源码的想法,所以就想到了在自己常用的Eclipse上可以调试JDK源码. 整个设置过程也很简单: 首先你要安装好JDK(我的JDK安装路径根目录是D:\Java\jdk-8u9 ...