The first day of the question on iOS

Source: Internet
Author: User

This morning, two companies were interviewed in the afternoon. Morning is an internet company, the atmosphere is still relatively good, I prefer. Technology this is a direct machine test, mainly to give some bug let me repair, the whole process is smooth. In the afternoon went to a large securities company. Finishing technical issues are as follows:

1. What is the life cycle of the uiview, and what is the order of execution?
Init--loadview--viewdidload--viewwillappear--viewwilldisappear--viewdidunload--dealloc.

2. When will the Uiviewcontroller load the UIView, in other words, at which point in time the Loadview will be executed.
I did not answer this question, originally wrote the program only know is in Addsubview or Pushviewcontroller time, the program will execute loadview. It was felt that Loadview was executed before the UIView was to be displayed. Later, I learned that this kind of statement is actually a bit outs down. It is because the loadview is executed, so UIView will be displayed. The correct answer is that the Loadview is executed when the View object is accessed for the first time.

3. What is the implementation process of UITableView?
Omit UIView related not to say, UITableView, each uitableview will have a delegate,delegate point to the object will accept UITableView delegate to implement a series of methods. Several of its main methods are executed in the following order:
Numberofsectionsintableview--numberofrowsinsection--titleforheaderinsection--cellforrowatindexpath

4. How does the UITableView implement cell reuse?
UITableView has an array, visiblecells, to save the visual cell. Suppose a screen can display 10 cells. When you swipe up TableView, the 1th cell moves out of the visual range and the 11th cell is displayed. If the cell is obtained by means of the Dequeuereusablecellwithidentifier method, it is essentially placing the first cell in the 11th position and then redrawing the content according to Indexpath's requirements . It does not clear the Subview in the cell. This is also why when Uilabel is added to the cell, there will be ghosting (multiple uilabel overlap) when pulling up and down. To avoid this situation, Apple recommends customizing the UITableViewCell. If you do not customize the cell, you can define different cellidentifier for different indexpath cells. Or every time you go through Subview, delete all the child views, addsubview them again, and so on.

5. How to design a variable height (according to the content adaptive height) UITableViewCell?
This is really a pain in the egg, I did not encounter such a demand, the practice is fixed high, and then the text content more, directly omitted, guide users click into the next layer to watch. At that time intermittent brain remnant said a sentence do not know, later think, really very simple:
When we were configurecell, we obtained the cgsize of Uilabel by Sizewithfont method, and then we obtained the height of the custom cell, then we can make the corresponding assignment in Heightforrowatindexpath. -_-!!!

6. Talk about the memory management mechanism.
The basic understanding of this is that Objective-c is retaincount to determine whether to reclaim memory. Each nsobject has a counter retaincount, when alloc, the value of Retaincount is 1, and each retain will add 1,release minus 1, when Retaincount is 0, memory will be released. This raises another question, what is the scope of the object that NSString created through stringwithstring? When will it be released? I think that the object created by the above static method is approximately equal to, [[[NSString Alloc] initwithstring:@ ""] autorelease]; That is to say, he is a Autorelease object, is put into the nsautoreleasepool. The system will establish a nsautoreleasepool for each runloop, and when the Runloop is finished, the memory in Autoreleasepool will be released.
Note: I confused the concept of closures and runloop when answering the questions, and Runloop was said to be a closed packet. We'll talk about the block later.

7. Talk about the understanding of block.
Block is the closing packet . A closure is a function or pointer to a function, plus its external variables (also called free variables). Block has three species, Nsconcreteglobal, Nsconcretestack, Nsconcretemalloc. A block is a variable that can be accessed outside the block.
Nsconcreteglobal: Just like a global function, it is always available to stay there from beginning to end. When no external variables are referenced in the block, the block is of type Global.
Nsconcretestack: The memory will be freed after the Block,block in the stack has been executed. When the block references an external variable, the block is of type stack.
Nsconcretemallock: The memory is freed when the Block,block in the heap is a reference count of 0 o'clock. When the block executes copy, the block is copied from the stack to the heap.
For non-ARC environments, blocks referencing external variables are automatically saved in the heap, without copy, in the ARC environment.

The current arrangement is so much, kvo,delegate and other design patterns are not discussed today. There are 7 companies interview waiting for the elder brother, the huge amount of paper to send a resume of the child can not afford to hurt AH. I will keep updating.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.