iOS 2016-side question three

Source: Internet
Author: User

1.OC Memory management mechanism

1). When you use the New,alloc and copy methods to create an object, the object's retention counter value is 1. When you no longer use the object, you are responsible for sending a release or Autorelease message to the object. This way, the object will be destroyed at the end of its useful life.

2). When you get an object in any other way, assume that the object has a retention counter value of 1, and that it has been set to auto-release, you do not need to do anything to ensure that the object is cleaned up. If you intend to have the object for a period of time, you need to keep it and make sure that it is released when the operation

3). If you keep an object, you need to (eventually) release or release the object automatically. You must keep the Retain method and the release method equal in number of uses.

2. What is the role of the agent and what are the advantages?

The purpose of the agent is to change or transfer the control chain. Allows a class to be notified to other classes at certain times without having to obtain pointers to those classes. You can reduce the complexity of the frame. Another point, the agent can be understood as a callback in Java a listener mechanism of a similar

Advantages: 1, to avoid the sub-class of too many subclasses and subclasses and the parent class coupling
2. Hierarchical decoupling via delegated message mechanism

3. Interface ID

Interface ID has two directions: A, the upper interface (the current interface) to the subordinate interface (to open the interface), then directly in the subordinate interface set the ID corresponding to the property, the superior interface in the sub-interface before opening, to the subordinate interface ID attribute assignment, B, the subordinate interface value to the upper interface, At this point the agent is used (this is not said), or block (block with ID parameter). The method is: the sub-interface defines a block, with the ID parameter, the upper interface to open the subordinate interface before the implementation of the block, the subordinate interface after triggering the corresponding event, call the Block

4. Remember your last browsing history

After entering the app, stay on the last screen. This is relatively simple, a few steps: A, after opening an interface, record the current interface (can be recorded in viewdidload); b, inside the Appdelegate (didfinishloading. That), find the records in a, if any, then assign the corresponding controller to the window's Rootviewcontroller (if there is a push, you have to build the controller layer by level, and then push it one by one to the corresponding interface)

Format of 5.Json

Assuming that the name is key, the age key is age:{"name": "Zhang San", "Aged": "20"}

JSON is a specification, a bit like nsdictionary, based on the key-value structure

The role of the 6.readwrite,readonly,assign,retain,copy,nonatomic attribute??????

1). ReadWrite is a readable writable feature that needs to generate getter and setter methods

2). ReadOnly is a read-only feature that generates getter methods only, does not generate setter methods, and does not want attributes to change outside of the class

3). Assign is an assignment attribute, the Setter method assigns the method passed to the argument to the instance variable, only when the variable is set

4). Retain represents the holding characteristics, setter method will pass in parameters first reserved, then assign value, the Retaincount of incoming parameter will +1

5). Copy represents an assignment attribute, and the setter method copies a copy of the incoming object, which requires a completely new variable. (for strings and blocks basically with copy, for strings, if the attribute is assigned to a mutable string, if you do not copy, then the changes in other places, the properties will change accordingly-if you do not want this, with copy; for block, Apply copy. Copy makes sure that the block in the attribute is assigned to the heap, that it is not error-free when it is called, and that if the block is allocated on the stack, it may be crash. "Heap: Application-level memory, where the heap is valid during the application lifecycle; Stack: Method-level memory, the stack is freed when the method call is finished")

6). nonatomic Non-atomic operation, determines whether the compiler generated setter, getter is atomic operation, atomic represents multithreading security, generally use nonatomic.

7. The role of categories, the difference between category and class extension

1). Spread the implementation of the class across multiple different files or multiple different frameworks.

2). Create a forward reference to the private method.

3). Add an informal agreement to the object.

Limitations of categories

There are two limitations:

1). Unable to add a new instance variable to the class, the category does not have a location to accommodate the instance variable.

2). Name conflicts, that is, when a method in a category conflicts with the original class method name, the category has a higher precedence. The class method will completely replace the initial method so that the initial method can no longer be used.

Limitations of the inability to add instance variables can be resolved using a Dictionary object

???? Difference: Extensions can add attributes, and the method that the latter adds must be implemented

Extensions can be thought of as a private (anonymous) category.

Several method invocation order in 8.Controller

1). In general, call the Init method or invoke the Initwithnibname method to instantiate the Uiviewcontroller

-(ID) Initwithnibname: (nsstring*) Nibnameornilbundle: (nsbundle*) Nibbundle Ornil

2). The Loadview method is then called to generate the Uiviewcontroller.view

-(void) Loadview

3). Then call Viewdidload

-(void) viewdidload

4). If Loadview cannot generate the Uiviewcontroller.view system will call Loadview and Viewdidload methods repeatedly, and eventually call the [super Loadview] method to return Uiviewcontroller . View

And then call the following 2 methods, these 2 methods are also very important, after the Uinavigationcontroller pop operation, sometimes the view in the Uiviewcontroller that will be displayed is not released (and may be released), Uiviewcontroller will not call the above three methods (Initwithnibname,loadview,viewdidload) and will call the following 2 methods
-(void) Viewwillappear: (BOOL) animated;
-(void) Viewdidappear: (BOOL) animated;

9. know the difference between frame and bounds, and know the role of center1). Frame refers to the position and size of the view in the parent view coordinate system (the reference point is the father's coordinate system) 2). Bounds refers to the position and size of the view in its own coordinate system (the reference point is its own coordinate system) 3). Center:cgpoint type That describes the location of the view's center point in the parent view coordinate system What is the difference between #import and # include, @class, #import <> #import "" ?#import is the keyword of objective-c import header file, #include is the key word of C + + import header file, using #import header file will automatically import only once, will not repeat import, equivalent to # include and #pragma once;

@class tell the compiler the declaration of a class, when executed, only to see the implementation of the class file, you can resolve the header file of the mutual inclusion;

#import <> header file to include the system

#impor "" To include a user header file or to import a library

11.POST and GET Requests

Send Get Request

1) Determine the request path (typically provided by the company's background developer as an interface document), and get request parameters directly following the URL

2) Create the Request object (which contains the request header and the request method "GET" by default), this step can omit

3) Create Session object (Nsurlsession)

4) Create a request task based on the Session object (Nsurlsessiondatatask)

5) Execute Task

6) When the response returned by the server is obtained, parse the data (xml| json| HTTP)

Send post Request

1) Determine the request path (typically provided by the company's background developer in the form of an interface document)

2) Create a mutable request object (because it needs to be modified), this step cannot be omitted

3) Modify the request method to post

4) Set the request body, convert the parameters into binary data and set the request body

5) Create Session object (Nsurlsession)

6) Create a request task based on the Session object (Nsurlsessiondatatask)

7) Execute Task

8) When the response returned by the server is obtained, parse the data (xml| json| HTTP)

Difference: 1). Get data with GET, upload data with POST.

2). But post is also available for data. Because both get and post are sending requests to the server. Only in the browser there is a difference get direct send URL, the requested parameters are on the URL, is clear text.

3). Post parameters, which are placed on the page, are not displayed in the address bar

4). Get URL length is limited, post can send more data

12.iOS various controls default height

1. Status bar

The status bar generally has a height of 20 pixels, and when you hit your phone or display a message, it zooms to 40 pixels high, noting that the status bar, which is twice times the height, appears to be only used in portrait mode.

2. Navigation bar

The navigation bar is 44 pixels high in portrait mode and 32 pixels high in landscape mode

3. Tabs, toolbars

The tab is 48 pixels high and the toolbar is 44 pixels high.

4. Keyboard

This is generally horizontal 320*216 pixels, 480*162 pixels vertically

Four types of data storage in IOS

    • Nsuserdefaults, for storing configuration information
    • SQLite for storing data with more demanding queries
    • CoreData, for planning objects in your app
    • Customized caching schemes using basic object types

14. Interrupt GCD

    1. Set a BOOL value outside, block inside read this value, for true exit

2. Nsoperation,nsoperation natively supports cancel, calling its Cancel method to

15.Const

1. Modifier variables

2. Modifier pointers

3. Frequently cited
Use more parameters to prevent parameters from being modified, reference to avoid creating a copy of the parameter

5. Constant function
is the member function of the class, and the argument is followed by a const, which does not allow the data members of the class to be modified

16.block Circular Reference problem--memory management

A block is strongly referenced in an object, and the object is used in the block, and a circular reference is emitted.

The workaround is to use the object with the __weak or __ block modifier before it is used in the block.

iOS 2016-side question three

Related Article

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.