Key Points of iOS development knowledge

Source: Internet
Author: User
About string:

1. convert an integer to an nsstring.

 
[Nsstring stringwithformat :@"% D", 3];

2. Compare whether two nsstrings are equal

 
[@"Test"Isequaltostring :@"Test"];

3, @ "abcdefg", truncate the first three characters

 
[@"Abcdefg"Substringwithrange: nsmakerange (1, 3)]

4. Differences and relationships between utf8 and Unicode

Here is a detailed explanation

5. Differences between nsstring and nsmutablestring

Nsstring, which cannot be modified
Nsmutablestring, which can be modified

6. Calculate the actual pixel height to be rendered when the specified width and font of a string are specified.

 
[@"Abcdefg"Sizewithfont: [uifont systemfontofsize: 12] constrainedtosize: cgsizemake (100, int32_max)]. Height

7. Use http to obtain the HTML data of www.baidu.com.

 
[Nsstring stringwithcontentsofurl: [nsurl urlwithstring :@"Http:// Www.baidu.com"]
Uiview and uiviewcontroller:

1. Differences between frame and bounds in uiview

Frame: location and size of the uiview instance
Bounds: displays the position and size of the internal content of the uiview instance.

2. briefly explain the functions of uitableviewdatasource and uitableviewdelegate in uitableview

Both are the protocols required by uitableview:
Uitableviewdatasource. You can define a data acquisition method for this tableview to provide a data source.
Uitableviewdelegate, used to define display styles and user event-related methods

3. Implement a transparent gradient animation effect with a background uiview, and move the animation effect

// Animation preparation starts[Uiview beginanimations :@"Animation"Context: Nil]; [uiview setanimationduration:. 5];// Animation of the rising ImageCgrect F = imgview. frame; f. Origin. Y = 30; imgview. Frame = F;// Translucent gradient AnimationImgview. Alpha = 0;// Submit an animation[Uiview commitanimations];

4. Make a uiimageview Image view object adaptive to stretch as it changes its frame.

 
Uiimageview * imgview = [[uiimageview alloc] initwithimage: [uiimage imagenamed :@"Test.png"]; Imgview. Frame = cgrectmake (0, 0,200,200); imgview. contentmode = uiviewcontentmodescaletofill;

5. Make a uiview object. After the screen is rotated, the live position remains unchanged, the left position is adaptive, And the size remains unchanged.

Uiimageview * imgview = [[uiimageview alloc] initwithimage: [uiimage imagenamed :@"Test.png"]; Imgview. Frame = cgrectmake (20, 20, 100,100); imgview. autoresizingmask = uiviewautoresizingflexibletopmargin;

6. The more design patterns used in uiview, the better ~

7. Use an attribute in the layer of uiview to implement a rounded corner view (quartz2d library needs to be introduced)

 
Self. View. layer. cornerradius = 5; self. View. clipstobounds = yes;

8. Role of contentsize in uiscrollview

Used to identify the position where the current content is displayed. The type is cgsize.

9. Relationship between uiviewcontroller and view, role in MVC Mode

One is the Controller layer, the other is the view layer, and the controller controls the display of the view.

10. list several system viewcontrollers

Uitabbarcontroller
Uinavigationcontroller
Uitableviewcontroller
Uiimagepickercontroller

11. Differences between drawrect and layoutsubviews in uiview,

When setneedsdisplay of view is called, the system asynchronously calls the drawrect method and prepares the image context for using the quartz2d API in this method.
When setneedslayout of view is called, The layoutsubviews method is called asynchronously, but the graphic context is not prepared, and only used for page layout.

12. Role of clipstobounds attribute in uiview

When the size of the Child view exceeds that of the parent view, if this value is yes, the excess part is hidden.

13. If the position of a sub-view in the uiview is outside the uiview, can the touchesbegan and other methods of the uiview be obtained?

Cannot be obtained

14. How to Determine the double-click operation

In the touchesbegan method, obtain the uitouch instance:
[[Touches anyobject] tapcount];

15. In the drawrect method of uiview, use the quartz2d API to draw a horizontal line with pixel width.

-(Void) drawrect :( cgrect) rect {// Obtain the image ContextCgcontextref context = uigraphicsgetcurrentcontext ();// Set the path Painting Color of the graphic ContextCgcontextsetstrokecolorwithcolor (context, [uicolor whitecolor]. cgcolor );// Fire-fighting sawtoothCgcontextsetallowsantialiasing (context, no );// Add a lineCgcontextmovetopoint (context, 50, 50); cgcontextaddlinetopoint (context, 100, 50 );// DrawCgcontextdrawpath (context, kcgpathstroke );}

16. Use uiwebview to load: www.baidu.com

 
Uiwebview * Web = [[uiwebview alloc] initwithframe: cgrectmake (0, 0,320,480)]; [web loadrequest: [nsurlrequest requestwithurl: [nsurl urlwithstring :@"Http:// Www.baidu.com"];[Self. View addsubview: Web]; [Web release];

17. Can the sub-thread also modify the uiview?

No. Only the main thread can directly modify the UI.
Memory related:

1. What is retain used for? What is the role it plays in memory management? What is the corresponding release method?

Add one to the instance reference count (retaincount). The corresponding release methods include release and autorelese.

2, nsobject * o = [[nsobject new] autorelease]; what is the retaincount of this object "O" after this sentence is executed?

1

3. explain the role of the NSAID pool in objective-C memory management.

The memory management pool enables objective-C to become a semi-automated memory management language.

4. briefly explain the Declaration in @ property, the difference between assign and retain, and implement a setter Method for declaring attributes in retain.

Both of them are declarations for the setter method, but only one of them.
Assign, indicating that the setter method is implemented only by pointer assignment.
The retain and setter methods must be implemented.
 
-(Void) setname :( nsstring *) _ name {If(Name! = _ Name) {[Name Release]; name = [_ name retain] ;}}

5, nsarray * arr = [nsarray array]; this arr object requires no release. Why?

No, because there are no retain, alloc, new, copy, and other methods.
This is a convenient method for cocoa to create objects. A retaincount of this instance has been placed in autoreleasepool.
Runtime and cocoa architecture:

1. ID: what is expressed in objective-C and what is the role

It can point to any instance type. It is a struct containing only one class ISA member pointer.
Typedef struct objc_class * Class ; Typedef struct objc_object { Class ISA;} * ID; struct objc_class { Class ISA ;# If ! _ Objc2 __Class Super_class objc2_unavailable; Const   Char * Name objc2_unavailable; Long Version objc2_unavailable; Long Info objc2_unavailable; Long Instance_size percent; struct objc_ivar_list * ivars percent; struct objc_method_list ** methodlists percent; struct objc_cache * cache percent; struct objc_protocol_list * protocols percent; # endif} percent;

2. Functions of nsarray, nsmutablearray, nsdictionary, nsmutabledictionary, and nsset

These are common containers used in the cocoa architecture to store instances for different purposes.
Nsarray is used to store a series of ordered instances. Once created, the modification list cannot be added.
Nsmutablearray is used to create an ordered instance of the variable Object List.
Nsdictionary, which stores key-value pairs, such as hash.
Nsset: stores unordered data.

3. nsnumber and nsvalue usage

Nsnumber, used to store value information related classes. This instance can be directly stored in the cocoa container.
Nsvalue, used to store data structures.

4. What is ISA in the structure definition of nsobject?

Is a Data Structure of the class type,
Struct objc_class { Class ISA ;# If ! _ Objc2 __ Class Super_class objc2_unavailable; Const   Char * Name objc2_unavailable;Long Version objc2_unavailable; Long Info objc2_unavailable; Long Instance_size percent; struct objc_ivar_list * ivars percent; struct objc_method_list ** methodlists percent; struct objc_cache * cache percent; struct objc_protocol_list * protocols percent; # endif} percent;

5. Objective-Dynamic Features and implementations of C language (runtime)

Http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Introduction/Introduction.html

6. How to determine whether an object is an instance of a class

 
[Testview iskindofclass: [uiview class];

7. How can I determine whether an object contains a specified method?

 
[Testview respondstoselector: @ selector (methodname)];

8. Use nstimer as a timer to print: Hello world every second.

 
-(Void) printhello {nslog (@"Hello world !! ");}-(Ibaction) clickbtn :( ID) sender {nstimer * timer = [nstimer scheduledtimerwithtimeinterval: 1 target: selfselector: @ selector (printhello) userinfo: Nil repeats: Yes]; [Timer fire];}

9. Use nsobject's javasmselectorinbackground to create a subthread, complete an HTTP request in the subthread, and display the request result on the screen.

Archive.zip

10. nsnotificenter: explains how to implement the observer mode.

Message distribution and registration center. It is used to manage the objects that register the listener in the message center and distribute the message to the listener listening for this event when an event occurs.
This is a typical Implementation of the observer mode. In our applications, in order to understand the coupling between modules, message centers are used in large quantities, and the collaboration between modules is driven by events and messages.

11. A brief description of the nsunloop

Http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html#//apple_ref/doc/uid/10000057i-CH16-SW1
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.