《iOS Programming》的原文摘录

  • 在便捷方法中,应该使用 self,而不是直接使用类名,这样子类也能使用同一个方法。 (查看原文)
    著名热心网友 2012-05-07 23:03:59
    —— 引自第55页
  • All Objective-C objects are stored in a part of memory called the heap. When we send an alloc message to a class, a chunk of memory is allocated from the heap. This chunk includes space for the object’s instance variables. Pointer variables convery ownership of the objects that they point to. 1. When a method (or function) has a local variable that points to an object, that method is said to own the object being pointed to. 2. When an object has an instance variable that points to another object, the object with the pointer is said to own the object being pointed to. The idea of object ownership helps us determine whether an object should be destroyed. 1. An object with no owners should be destroyed. An ownerless object cannot be sent messages and is isolated and useless to the application... (查看原文)
    厚积薄发 2012-08-25 18:36:48
    —— 引自第51页
  • How objects lose owners 1. A variable that points to the object is changed to point to another object. 2. A variable that points to the object is set to nil. 3. A variable that points to the object is itself destroyed. A pointer variable stores the address of an object, that object has an owner and will stay alive. This is known as a strong reference. However, a variable can optionally not take ownership of an object it points to. A variable that does not take ownership of an object is known as a weak reference. A weak reference is useful for an unusual situation called a retain cycle. A retain cycle occurs when two or more objects have strong references to each other. This is bad news. When two objects own each other, they will never be destroyed by ARC. Even if every other object in th... (查看原文)
    厚积薄发 2012-08-25 18:36:48
    —— 引自第51页
  • Build and run the application again. This time, the objects are destroyed properly. Every retain cycle can be broken down into a parent-child relationship. A parent typically keeps a strong reference to its child, so if a child needs a pointer to its parent, that pointer must be a weak reference to avoid a retain cycle. (查看原文)
    厚积薄发 2012-08-25 18:36:48
    —— 引自第51页
  • A property is declared in the interface of a class where methods are declared. A property declaration has the following form: @property NSString *itemName; When you declare a property, you are implicitly declaring a setter and a getter for the instance variable of the same name. So the above line of code is equivalent to the following: - (void)setItemName:(NSString *)str; - (NSString *)itemName; (查看原文)
    厚积薄发 2012-08-25 20:16:31
    —— 引自章节:Properties
  • Delegation is an object-oriented approach to callbacks. A callback is a function that is supplied in advance of an event and is called every time that event occurs. Some objects need to make a callback for more than one event. For instance, the location manager wants to "callback" when it finds a new location and when it encounters an error. However, there is no built-in way for two (or more) callback functions to coordinate and share information. This is the problem addressed by delegation – we supply a single delegate to receive all of the event messages for a particular object. This delegate object can then store, manipulate, act on, and relay the related information as it sees fit. (查看原文)
    厚积薄发 2012-09-01 14:30:14
    —— 引自章节:delegate
  • A view is an instance of UIView or one of its subclasses. A view knows how to draw itself on the application’s window, an instance of UIWindow. A view exists within a hierarchy of views. The root of this hierarchy is the application’s window. A view handles events, like touches. Core Graphics CGContextStrokePath will draw a line along the path. CGContextFillPath will fill the shape made by the path. CGContextClip will limit future drawing operations to the area defined by the path. For example, drawing a square to a context that has been clipped to a circle of the same size will result in drawing a circle. View subclasses send themselves setNeedsDisplay when their drawable content changes. The redrawing of a view’s image is not immediate; instead, it is added to a list of views that need... (查看原文)
    厚积薄发 2012-09-01 23:24:43
    —— 引自章节:Subclassing UIView and UIScrol
  • Instances of UIResponder can become the first responder of the window and will receive nevents when the device is shaken or a key is pressed on the keyboard. (查看原文)
    厚积薄发 2012-09-01 23:24:43
    —— 引自章节:Subclassing UIView and UIScrol
  • XIB文件是XML格式的文本文件,用于保存固化后的对象。build项目的时候Xcode会把XIB文件编译成NIB文件,开发者维护XIB文件,应用使用NIB文件。 (查看原文)
    小葱葱 2012-12-29 21:15:49
    —— 引自第5页
  • 如何创建并设置对象(例如,在某处放置一个按钮并将其标题设置为“显示时间”)? 如何处理用户交互(例如,在用户按下某个按钮时执行某段代码)? (查看原文)
    黑涩布朗尼 2013-03-14 13:47:31
    —— 引自第1页
  • QuizViewController的任务之一是当用户按下Show Question按钮时,显示一道新题目。按下该按钮会触发QuizViewController实例的某个方法(Method),这个方法会从Questions数组里取出一道新题目,然后通过位于试图上访的标签将题目显示出来。 (查看原文)
    黑涩布朗尼 2013-03-14 14:13:37
    —— 引自第10页
  • The book is misleading in that it gives the specific example above with the NSMutableString (Loc 2631 in the Kindle version), saying that adding the "copy" attribute to the itemName property will protect it from NSMutableStrings from messing up the immutable property of BNRItem. The thing is, they never ask you to either 1) change the init method to either use the itemName accessor, or 2) change the init method to use explicitly copy. (查看原文)
    amov 2015-09-02 13:58:35
    —— 引自第80页
  • 类似地,在用户删除了某个BNRItem对象后,需要同时在BNRImageStore对象中删除对应的UIImage对象。在BNRDetailViewController.m顶部导入BNRImageStore.h,然后修改removeItem:方法 (查看原文)
    华尔街喜之郎 2015-10-19 00:53:18
    —— 引自章节:第11章 相机 第5节 创建并使用键