<ios Development of Advanced > Dry Goods Summary

Source: Internet
Author: User

Before reading the <ios development of advanced, and also made a corresponding summary, see: Read <ios Development advanced > Thoughts

Take some time today, put together some dry goods, and then you can and this book say goodbye.

Including:

    1. P85 10.1.3
    2. P96 after using GCD
    3. P99 Background Run
    4. p131 using Safari for debugging
    5. p184 to close the keyboard
    6. p185 Setting the System control language within the app
    7. p193 ignoring compilation warnings
    8. p198 add a picture to the simulator album


10.1.3 do not send messages to objects that have already been disposed
Some readers want to test whether the Retaincount becomes 0 when the object is released, and their test code is as follows: (Remember to set it to Mrc-fno-objc-arc in APPDELEGATE.M)
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{    Override point for customization after application launch.        NSObject *object = [[NSObject alloc] init];    NSLog (@ "Reference Count =%u", [object Retaincount]);        [Object release];    NSLog (@ "Reference Count =%u", [object Retaincount]);    return YES;} Print result//2015-01-21 10:04:05.799 mrc_test[2985:607] Reference Count = 1//2015-01-21 10:04:05.800 mrc_test[2985:607] Refe Rence Count = 1

We noticed that the last output, the reference count did not become 0. Because the object's memory has been reclaimed, and we send a RETAINCOUNT message to an object that has been reclaimed, its output should be indeterminate, and if the memory used by the object is reused, it can cause the program to crash unexpectedly. So why is this indeterminate value 1 instead of 0 after the object is recycled? This is because when the last release was executed, the system knew that it was about to reclaim the memory immediately. There is no need to reduce the retaincount by 1, because the object will definitely be recycled, regardless of the 1 reduction. When the object is recycled, all of its memory areas, including the Retaincount value, also become meaningless. By not changing this value from 1 to 0, you can reduce the amount of memory that occurs once and speed up the collection of objects.

After using GCD






11.2.4 Background Run
Another use of block is to allow the program to run more permanently in the background. Previously, when the app was pressed to exit, the app had a maximum of 5 seconds to do some work to save or clean up resources. However, the app can call UIApplication's Beginbackgroundtaskwithexpirationhandler method, allowing the app to run for up to 10 minutes in the background for a long time. This time can be used to clean up the local cache, send statistics and other work.
Appdelegate.h
@property (Assign, nonatomic) Uibackgroundtaskidentifier backgroundupdatetask;

Appdelegate.m
launchoptions{//Override point for customization after application launch. return YES;} -(void) Applicationwillresignactive: (uiapplication *) application{//Sent when the application was about to move from AC tive to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US    Er quits the application and it begins the transition to the background state. Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should with this method to pause the game.}        -(void) Applicationdidenterbackground: (uiapplication *) application{[self beginbackgroundupdatetask]; Add code that needs to run long [self endbackgroundupdatetask];} -(void) beginbackgroundupdatetask{self.backgroundupdatetask = [[UIApplication sharedapplication]    beginbackgroundtaskwithexpirationhandler:^{[self endbackgroundupdatetask]; }];} -(void) endbackgroundupdatetask{[[UiapplIcation sharedapplication] EndBackgroundTask:self.backgroundUpdateTask]; Self.backgroundupdatetask = Uibackgroundtaskinvalid;}




15.7 Using Safari for debugging






18.2.2 to close the keyboard


In addition to the Resignfirstresponder method of invoking the corresponding control, there are three other ways to uiviewcontroller the keyboard in the box:

1. Reload the Touchesbegin method in the Uiviewcontroller, then execute [self.view Endediiting:yes] inside; You can then click anywhere in the Uiviewcontroller to close the keyboard.

2. Direct execution [[uiapplication sharedapplication] sendaction: @selector (resignfirstresponder) To:nil From:nil Forevent:nil]; Used when getting the current uiviewcontroller more difficult.

3. Direct execution [[[UIApplication sharedapplication] Keywindow] Endediting:yes]



18.2.4 Setting the System control language within the app


In iOS apps, there are times when you need to invoke some UI controls on your system, such as:

1. In UIWebView, press and hold the context menu of the popup system.

2. The system's camera interface is used in Uiimagepickercontroller.

3. In the compilation state of the UITableViewCell, in the pending deletion state, there will be a system delete button.


These UI controls, which are not displayed in the same language as the system language of your current phone, are displayed according to the language settings within your app.


In the Info.plist file, add:

Cfbundlelocalizations ZH_CN



18.2.9 ignoring compilation warnings


Use-W disables all compilation warnings, and-wno-unused-variable only suppresses compilation warnings that do not use variables.

(same usage as-FNO-OBJC-ARC)



18.4.3 add a picture to the simulator album


... Drag and drop the picture directly into the simulator and use Safari to open it and save it.


<ios Development of Advanced > Dry Goods Summary

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.