iOS Basics Questions Series (i)-answer

Source: Internet
Author: User
Tags abstract language word wrap

"tim's blog"ios basic question and Answer Question series (a)-with answers

"tim's blog"ios basic question and Answer Question series (ii)-with answers

"tim's blog"ios basic question and Answer question series (iii)-with answers

"tim's blog"ios basic question and Answer question series (iv)

Here are some of the more basic questions you collect (the big God can ignore), with an answer that's easy for everyone to read. As the saying goes, the foundation is not good, shake. At the end of the article will provide a PDF version of the document, so that everyone can use the network when the mobile device to watch.

1. Describe the differences between class extensions and classifications in a nutshell? (say 2 points)
    • The class extension has no name, and the category has a name.
    • A class extension can add additional attributes, member variables, method declarations for a class, a taxonomy can only extend a method, cannot extend a member variable, and if an attribute is declared in a taxonomy, the classification generates only the Get\set method declaration for that property.

2. A brief description of the difference between the frame and the bounds of UIView.
    • Frame represents the position and dimensions of the control rectangle in the parent control, which is the origin of the coordinates in the upper-left corner of the parent control.
    • Bounds represents the position and dimensions of the control rectangle, which is the origin of the coordinates in its upper-left corner.

3. What is a controller
    • All objects that inherit from Uiviewcontroller are controllers.

4. Simple description of the function of the controller
    • Responsible for handling various events of the software interface, and responsible for the creation and destruction of the software interface.

5. Simple description of the role of the storyboard
    • Used to describe the software interface.

6. Briefly describe the starting principle of the program
    • When the program starts, the Main.storyboard file is loaded, the controller that the arrow refers to is created, and the software interface that the controller manages is displayed

What does 7.IBOutLet do?
    • Properties that are modified by Iboutlet can be dragged into storyboard and can only be decorated with attributes.

What does 8.IBAction do?
    • Methods that are modified by ibaction can be dragged into the storyboard, only the method return value type can be modified

What does the 9.IBAction and Iboutlet prefix IB mean
    • IB full Name: Interface builder, starting with XCODE4, Interface Builder has been integrated into Xcode

10. Simple description of parent-child controls
    • Each control is a container that can hold other controls; the inner gizmo is a child of the large control; The large control is the parent control of the inner gizmo

11. Explain the meaning of each option when referencing resources
    • Copy: Tick copy to copy the resources into the project's folder (it is recommended that you modify the resources in the project without affecting the source resources)
    • Added folder: If you check create groups, only a virtual folder will be created, after the program is packaged, the folder does not exist in the installation package, if you check Create folder references, you really created a There is really this folder in the installation package.
    • Add to targets: Do you want to pack the resources into the software installation package? Be sure to tick, do not tick when the program is packaged, the installation package does not have this resource.

12.UILabel how to set up line wrapping
    • Set NumberOfLines to 0.
The difference between 13.Character wrap and word wrap
    • Character wrap character Wrap;
    • Word wrap word Wrap < guarantee the integrity of the word;.

The role of 14.contentMode
    • Content mode: Typically used to control how images are displayed

15.initWithImage: What's the role?
    • Creates a Uiimageview object based on the incoming picture object, and the size of the Uiimageview is equal to the size of the picture by default

16. How do I modify the Frame property of a control?
    1. Directly using the CGRectMake function
    2. Take advantage of temporary struct-body variables
    3. Direct use of structure assignment

17. How do I draw the method?
    • Draw the same code into the method first
    • Change things to variables, then compile, set the error to the parameters of the method

18. Via imagenamed: What are the characteristics of this method for loading pictures?
    • Have cache

UIImage *image =[uiimage imagenamed:@ "picture name"]

    • Use occasions: Pictures relatively small, the use of high frequency ratio
    • Recommendation: Place images that need to be cached in Images.xcassets

19. Developing how to choose Uilabel,uiimageview,uibutton
    • can use Uilabel,uiimageview as far as possible with Uilabel,uiimageview; need to interact with the user UIButton

20. What is a custom control
    • A control that inherits from the system writes its own control to encapsulate the details inside the control
21. How do I customize controls through code? And simply describe the reason for each step?
    • Create a new class that inherits UIView (the so-called custom control is a control that inherits from the system and writes one of its own)
    • Add child controls in the initWithFrame method (to make sure that someone else is out there, whether through Init or initwithframe creation, you can add child controls, because the Init method internally calls initWithFrame
    • Set the child control's frame in the Layoutsubviews method (because the size of the current control in the initWithFrame method may not be a value, so the position and size of the child control cannot be computed, and in the Layoutsubviews method, the size of the current control can be obtained)
    • Provides a model property that overrides the set method of the Model property (guaranteed to have the data set to the corresponding child control at the moment the data is set)
22. What is a model
    • Concept: An object dedicated to storing data
    • Features: General inheritance NSObject, declare some properties to hold data in the. h file
23. How do I customize a control by Xib? And simply describe the reason for each step?
    1. Create a new class that inherits UIView (the so-called custom control is a control that inherits from the system and writes one of its own)
    2. Create a new Xib file (the file name of the Xib is best as the class name)
    3. Modify the outermost control's class to be the name of the control (only modify the class name, when the time comes out of the xib is my type of control)
    4. Provides a model property that overrides the set method of the Model property (guaranteed to have the data set to the corresponding child control at the moment the data is set)

The difference between 24.instancetype and ID
    • can represent any type
    • Instancetype only as return value
    • The ID type can be either a return value or a parameter, or you can define a variable
    • Instancetype type detection, id not for type detection

The use of @property policy
    • Assign: Non-OC objects such as ' basic data type ', ' enum ', ' struct '
    • Weak:oc object types (such as Nsarray, NSDate, NSNumber, model classes)
    • Strong:oc object types (such as Nsarray, NSDate, NSNumber, model classes)
    • An object is not destroyed if it has a strong pointer reference

26. What are the benefits of lazy loading?
    • When loaded, it will only load once

27. If you are creating a control through Xib or storyboard, can the initialization action be done in the initWithFrame: Method?
    • If a control is created through Xib or storyboard, initWithFrame is not called when initialized, and Initwithcoder is called. The Awakefromnib method is called when initialization is complete, and it is recommended to initialize in awakefromnib

28. Does creating a control with Alloc/init or alloc/initwithframe actively load the xib?
    • Creating a control with Alloc/init or alloc/initwithframe does not actively load xib, even if the name of the Xib is the same as the class name of the control
29. Why is it possible to use weak when referencing UI controls with one property?
    • Because a UI control is added to the parent control, there is a strong pointer to the object and it should be guaranteed that the object will not be destroyed. In a property reference to this object, use a weak reference.
30. How do I hide a control?
    • Set hidden to Yes;
    • Set Alpha to 0.0.

31. How to use the button to achieve the effect of the text on the picture?
Custom button, implementation-(CGRect) Titlerectforcontentrect: (cgrect) contentrect{//return text frame}-  (cgrect) Imagerectforcontentrect: (CGRect) contentrect{//returns the Frame}-custom button of the picture, implements the Layoutsubviews method adjust the position and size of the inner child control of the button

32. How is the internal margin set by the code?
Self.btn.contentEdgeInsets = uiedgeinsetsmake (0, 0), self.btn.titleEdgeInsets = Uiedgeinsetsmake (0,-30, 0, 0); Self.btn.imageEdgeInsets = Uiedgeinsetsmake (0,-30, 0, 0);

33. How do I handle picture stretching issues?
Create an extruded Picture object BG = [bg resizableimagewithcapinsets:uiedgeinsetsmake (10,10,10,10) resizingmode:..];/ /tiling and stretching uiimage *bg = ...

34. How do I configure stretched pictures in Xcode?
    • Select Picture---> Right (slicing)-->sices:horizontal and Vertical up and down

The role of 35.KVC?
    • Key value Coding The value of the key, you can modify the values of the property, and you can modify the private member-specific variables;

36. How to monitor scrollview stop scrolling?
    1. Set up a proxy for ScrollView
    2. Proxy Object Compliance <UIScrollViewDelegate> protocol
    3. Implementation protocol Inside
-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate-(void) Scrollviewdidenddecelerating: (Uiscrollview *) ScrollView

37. What does a timer usually do? and how to use the timer
    • Can do an event every time.
      Pass
+ (Nstimer *) Scheduledtimerwithtimeinterval: (nstimeinterval) TI target: (ID) atarget selector: (SEL) Aselector UserInfo :(nullable ID) UserInfo repeats: (BOOL) Yesorno;

A Timer object that can create a custom execution task

Pass-(void) Invalidate this method to stop the timer

38.scrollView Usage Scenarios
    • When the content data is more than one can be displayed in a visual view, the Uiscrollview control needs to be used.

Why 39.UIScrollView can't scroll
    1. Contentsize is not set, or contensize is less than or equal to ScrollView size
    2. scrollenable = NO;
    3. userinteractionenable = NO; Whether to allow user interaction

The difference between 40.scrollEnable and userinteractionenable
    1. Scrollenable just can't scroll, other events can still respond
    2. Userinteractionenable prohibit any interactive events

The role of 41.alwaysBounceVertical Alwaysbouncehorizontal
    • No matter if there is no contentsize, there is always a spring effect; function: Used to do the drop-down refresh and pull-up refresh

42. How to monitor uiscrollview various behaviors
    1. Set the ScrollView delegate (proxy) as the Controller object
    2. Controller to comply with protocol Uiscrollviewdelegate protocol
    3. Controller to implement the Uiscrollviewdelegate protocol inside the method

43. Agent's attention Point
    1. The ScrollView agent can be any type of OC object
    2. Agent must be weak.

44. How to achieve content scaling with Uiscrollview
    1. Set up Proxy
    2. Implementing Proxy methods
      -(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView;
    3. Set the zoom ratio
      Self.scrollView.maximumZoomScale = 2.0;self.scrollview.minimumzoomscale = 0.2;
45. How do I monitor the behavior of a control?
    1. by Addtarget:
      This function is only possible if you inherit from an object from Uicotrol.
    2. By delegate:
      Only controls that have the delegate property have this function

46. How do I implement Uilabel package content through AutoLayout?
    1. Set Location constraints
    2. Set width constraint <= fixed value
    3. No need to set height constraints

47. What is a fit?
    • Adaptable and compatible with a variety of situations
    • System adaptation: Adaptable to different versions of the operating system
    • Screen fit: Suitable for different sizes of screen sizes

48. Differences in dots and pixels
    • In the eyes of the user, the screen is made up of countless pixels, the more pixels, the clearer the screen
    • In the eyes of the developer, the screen is made up of countless dots, which are made up of pixels, and the more pixels a O ' clock contains, the clearer the screen.

49. What is AutoLayout?
    • AutoLayout is an "automatic layout" technique designed for the layout of UI interfaces.

50. Briefly describe the 2 core concept constraints and references under AutoLayout
    • Constraints: Determine the position and size of a control by adding a constraint to the control
    • Reference: When adding a constraint, who will add it (can be a parent control or a sibling control)

51.Autolayout Warnings and Errors
    • Warning: The control's frame does not match the constraint added
    • Error:1> lack of necessary constraints;2> two constraint conflicts

52. The principle of adding constraints through code
    1. For a constraint relationship between two view levels, add to their parent view
    2. For the constraint relationship between two different levels of view, add to their nearest common parent view
    3. For a hierarchical relationship between the two view constraints, added to the higher level of the parent view

53. What is the VFL?
    • The VFL full name is visual format Language, which translates to "visual formatting language".
    • The VFL is an abstract language that Apple has introduced to simplify AutoLayout coding

54. By constraining how animations are implemented
    • Once you have modified the constraint, you can animate it by simply executing the following code
[UIView animatewithduration:1.0 animations:^{[added a constrained view's parent control layoutifneeded];

55. Specific implementation of performance optimization
    • When the list is scrolled, some UITableViewCell are moved out of the window, and UITableView the UITableViewCell outside the window into an object pool for reuse.
    • When UITableView requires DataSource to return UITableViewCell, DataSource will look at the object pool first, if there are unused uitableviewcell in the pool, DataSource will configure the UITableViewCell with the new data and return it to the UITableView and back to the window to avoid creating new objects.

How does 56.UITableView display data?
    1. Set Data source Object self.tableView.dataSource = self;
    2. Data source object to comply with protocol
    3. Implementing a Data source method
How many sets of data-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview;//How many rows of data are in each group-(Nsinteger) TableView: ( UITableView *) TableView numberofrowsinsection: (nsinteger) section;//What each line shows-(UITableViewCell *) TableView: ( UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath;

What kinds of styles are available in 57.UITableView
    • Uitableviewstyleplain
    • uitableviewstylegrouped

58.UITableViewController of understanding
    • Tableviecontroller has a TableView attribute, which points to a tableview, And TableView's DataSource and delegate attributes point to this controller. And this controller has complied with the Uitableviewdatasource and uitableviewdelegate protocols. Each controller has a view property inside it , in Tableviecontroller, the View and TableView properties point to the same object.

59. The idea of performance optimization
    • iOS devices have limited memory, and if you use UITableView to display thousands of data, you need thousands of UITableViewCell objects, which will deplete the memory of your iOS device. To work around this problem, you need to reuse the UITableViewCell object

Implementation steps for 60.UITableView performance optimization
/**  This method is called whenever a cell enters the field of view */-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: ( Nsindexpath *) indexpath{//1. Define a reuse identity static nsstring *id = @ "Tim";//2. Go to the cache pool to take recyclable celluitableviewcell *cell = [TableView dequeuereusablecellwithidentifier:id];//3. Cache pool If you do not have a recyclable cell, create your own if (cell = = nil) {cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:id];//Recommendation: All cells are the same setting, written in this curly brace; All cells do not have the same settings written on the outside Cell.backgroundcolor = [Uicolor redcolor];} 4. Set Data Cell.textLabel.text = [NSString stringwithformat:@ "%zd row data", Indexpath.row];return cell;}

61.registerClass: The role of
    • Register this ID with an ID to identify the corresponding cell type.

62. How to implement cell reuse by means of registration

NSString *id = @ "Wine";-(void) viewdidload {[Super viewdidload];//Registration ID This ID corresponds to the cell type Uitableviewcell[self.tableview Registerclass:[uitableviewcell class] forcellreuseidentifier:id];} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//1. Go to the cache pool first to find the recyclable celluitableviewcell *cell = [TableView dequeuereusablecellwithidentifier:id];//2. Set Data Cell.textLabel.text = [NSString stringwithformat:@ "%zd row of data", Indexpath.row];return cell;}

63. How to listen for TableView internal cell click events
    1. Set up Proxy
    2. Proxy Object Compliance Protocol
    3. Implement the method inside the Protocol

64. Brief descriptionregisternib: (Nullable uinib *) nib Forcellreuseidentifier: (NSString *) identifier and registerclass: (Nullable Class) Cellclass forcellreuseidentifier: (NSString *) identifier The difference between the 2 methods
    • RegisterClass This method is to register the corresponding cell type according to the ID, the system creates the cell by alloc/initwithstyle ...
    • Registernib This method is to register a xib file based on the ID, the system creates the cell by loading the Xib file.

65. How do I calculate the width and height of a piece of text?
    • The first case: if the label has only one row, by Sizewithattributes: This method, tell the text of the font and font size can calculate the size of this paragraph of text.
    • The second case: if the label needs a newline calculation height, by BoundingRectWithSize:options:attributes:attributes context: This method tells the font and font size of the text, and calculates the size of the text within a limited size.

66. What is a custom cell?
    • Inherit from the system UITableViewCell write a cell of your own

67. Custom cells by code can I add child controls to the Ininwithframe: Method?
    • No, the custom cell is in the Initwithstyle:reuseidentifier: method to add child controls

68. Custom cells by code can I calculate the position and size of the child controls in the Initwithstyle:reuseidentifier: Method?
    • No, because in this method, the cell size may not be available, and the position and size of the calculated child controls need to be computed relative to the cell. Custom cells by code are calculated in Layoutsubviews

69. What is the difference between customizing Cell,frame and Autolayout2 in code?
    • These 2 methods, except that the location and size of the child controls are determined differently. Frame is determined by setting the frame of the child control, whereas AutoLayout is determined by adding a constraint

70. How to load the cell by means of storyboard
    • First, according to the ID to the cache pool, if not in the cache, there is no registration, will automatically go to storyboard to find the ID of the cell, if any, the cell will be loaded, and bind this identity to return

71. Dictionary-to-model understanding of third-party frameworks
    • Mantle: All models must inherit from Mtmodel
    • Jsonmodel: All models must inherit from Jsonmodel
    • Mjextension: No need to force inheritance of any other class

72. Issues to be considered in the design framework
    • Invasive: Aggressive means it's hard to get out of this frame.
    • Ease of use: such as a small number of code implementation n Multifunction
    • Extensibility: It's easy to add new features to this framework

[Reply] PDF file Download [/reply]

iOS Basics Questions Series (i)-answer

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.