1.iOS is there a garbage collection?
OBJECTIVE-C 2.0 also has a garbage collection mechanism, but it can only be used in versions of Mac OS X Leopard 10.5 or more.
2.tableView reuse mechanism?
Viewing the UITableView header file, you will find nsmutablearray* visiablecells, and nsmutabledictnery* reusabletablecells two structures. Save the cells,reusabletablecells cells that are currently displayed in Visiablecells.
At the beginning of TableView display, Reusabletablecells is empty, then TableView Dequeuereusablecellwithidentifier:cellidentifier returns nil. The starting cell is created by [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:cellidentifier], And Cellforrowatindexpath just calls the maximum number of cells to display.
For example: There are 100 data, iphone one screen display up to 10 cells. The scenario at which the program initially shows TableView is:
(1). Create 10 cells with [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:cellidentifier], and assign the same reuse identity to the cell (of course, you can specify different identities for cells of different display types). And all 10 cells are added to the Visiablecells array, and the Reusabletablecells is empty.
(2). Drag the TableView down, when Cell1 completely out of the screen, and CELL11 (it is also alloc out, the reason above) is fully displayed. Cell11 joins to Visiablecells,cell1 to move out visiablecells,cell1 to join to Reusabletablecells.
(3). Then drag down TableView, because Reusabletablecells already has values, so when it's time to show the new Cell,cellforrowatindexpath is called again, TableView Dequeuereusablecellwithidentifier:cellidentifier, return to CELL1. Cell1 joins the VISIABLECELLS,CELL1 to move out of the reusabletablecells;cell2 to move out visiablecells,cell2 join to Reusabletablecells. Cells that need to be displayed later can be reused normally.
When are 3.ViewController's Loadview, Viewdidload, and Viewdidunload called, and what should be done in these functions when customizing Viewcointroller?
Starting with the relationship between Init, Loadview, Viewdidload, Viewdidunload, and Dealloc:
Init method
Instantiate the necessary objects in the Init method (follow the lazyload idea)
Initialize the Viewcontroller itself in the Init method
Loadview method
Viewcontroller calls this method when the view needs to be displayed and it is nil. Do not call the method directly.
If you manually maintain views, you must override this method by overloading
If you use IB to maintain views, you must not override this method with overloading
Loadview and IB Build view
You implement the Loadview method in the controller, then you may be called by the memory management control at some point when the application is running.
If the device is low on memory, the view controller receives a didreceivememorywarning message.
The default implementation is to check whether the current controller's view is in use.
If its view is not inside the view hierarchy currently in use and your controller implements the Loadview method, the view will be release and the Loadview method will be re-used to create a new view.
Viewdidload method
Viewdidload This method is called only when view is initialized from the nib file.
Overloads override this method to further customize the view
In iphone OS 3.0 and later versions, you should also overload the rewrite Viewdidunload to release any indexes on the view
Call data Model after Viewdidload
Viewdidunload method
This method is called when the system memory is tight (note: Viewcontroller is not dealloc)
When memory is tight, didreceivememorywarning is the only way to free up unused memory before iphone OS 3.0, but OS 3.0 and later viewdidunload methods are a better way
In this method, all Iboutlet (either property or instance variables) are set to nil (the System release view has already been removed)
When you release other view-related objects in this method, other objects created at run time (but not system-required), objects created in viewdidload, cached data, and other release objects, the object is set to nil (Iboutlet only need to be set to nil. System release view has been removed)
It is generally assumed that viewdidunload is a viewdidload mirror, because Viewdidload is also re-executed when view is re-requested
The Viewdidunload object must be an object that is easily recreated (such as an object created in Viewdidload or other methods), and do not release user data or other objects that are difficult to re-create
Dealloc method
Viewdidunload and Dealloc methods are not associated, dealloc still do what it's supposed to do
When was the 4.ViewController didreceivememorywarning called? What is the default action?
When the program receives a memory warning, the view controller will receive this message: didreceivememorywarning
Starting with iOS3.0, you do not need to overload this function to put the freed memory code into the viewdidunload.
The default implementation of this function is to check if the controller can safely release its view (here The bold view refers to the controller's view property). For example, view itself is not superview and can be easily reconstructed (from nib or Loadview function).
If view can be released, then this function frees the view and calls Viewdidunload.
You can overload this function to release other memory used in the controller. But remember to call the super implementation of this function to allow the parent class (typically Uiviewcontroller) to release the view.
If your viewcontroller holds a reference to the view's child view, you should release these references in this function in the earlier versions of iOS. In iOS3.0 or later, you should release these references in Viewdidunload.
5. How do you understand MVC, and how is MVC implemented in cocoa?
The MVC design pattern considers three types of objects: Model objects, view objects, and controller objects. Model objects represent special knowledge and expertise that are responsible for preserving the data of the application and the logic that defines the operational data. The View object knows how to display the model data for the application and may allow the user to edit it. The Controller object is the coordinator between the application's view object and the Model object.
Viewcotroller
Xib
What is the difference between 6.delegate and notification, and under what circumstances are they used?
KVC (key-value-coding)
KVO (key-value-observing)
Understanding KVC and KVO (key-value-encoding and key-value-monitoring)
When invoking an object through KVC, such as: [Self valueforkey:@ "Somekey"], the program automatically attempts to parse the call in several different ways. First find whether the object with Somekey this method, if not found, will continue to find whether the object with Somekey this instance variable (iVar), if not found, the program will continue to attempt to invoke-(ID) Valueforundefinedkey: This method. If this method is not implemented, the program throws a Nsundefinedkeyexception exception error.
(Key-value coding Find method, not only will find Somekey this method, but also find Getsomekey this method, preceded by a get, or _somekey and _getsomekey these forms. At the same time, finding the instance variable will not only look for the variable somekey, but also find out if the _somekey variable exists. )
Design Valueforundefinedkey: The main purpose of the method is that when you use the-(ID) Valueforkey method to request a value from an object, the object can have a last chance to respond to the request before the error occurs.
iOS interview (3)