iOS编程(第4版)
最新书摘:
-
华尔街喜之郎2015-10-19类似地,在用户删除了某个BNRItem对象后,需要同时在BNRImageStore对象中删除对应的UIImage对象。在BNRDetailViewController.m顶部导入BNRImageStore.h,然后修改removeItem:方法
-
amov2015-09-02The 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.
-
黑涩布朗尼2013-03-14QuizViewController的任务之一是当用户按下Show Question按钮时,显示一道新题目。按下该按钮会触发QuizViewController实例的某个方法(Method),这个方法会从Questions数组里取出一道新题目,然后通过位于试图上访的标签将题目显示出来。
-
黑涩布朗尼2013-03-14如何创建并设置对象(例如,在某处放置一个按钮并将其标题设置为“显示时间”)?如何处理用户交互(例如,在用户按下某个按钮时执行某段代码)?
-
小葱葱2012-12-29XIB文件是XML格式的文本文件,用于保存固化后的对象。build项目的时候Xcode会把XIB文件编译成NIB文件,开发者维护XIB文件,应用使用NIB文件。
-
厚积薄发2012-09-01Instances 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-01A 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 GraphicsCGContextStrokePath 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-01Delegation 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-08-25A 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 tothe following:- (void)setItemName:(NSString *)str;- (NSString *)itemName;
-
厚积薄发2012-08-25Build 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 itsparent, that pointer must be a weak reference to avoid a retain cycle.
-
厚积薄发2012-08-25How objects lose owners1. 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-25All 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-05-07在便捷方法中,应该使用 self,而不是直接使用类名,这样子类也能使用同一个方法。