1. the mutable data type cannot be declared as copy attributes, such as @ property (nonatomic, copy) nsmutablearray * array; @ property (nonatomic, copy) nsmutabledictionary * dict, then there will be problems during initialization, self. array = [[nsmutablearray alloc] init]; in fact, it is an nsarray instance in the memory. So it must be mutablecopy.
2. If the following code shows a modal UI, which contains uitextfield or uitextview members, the keyboard will appear. If you send a resignfirstrr0000der, the keyboard will not disappear.
UINavigationController *nv = [[UINavigationController alloc] initWithRootViewController:searchVC]; nv.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:nv animated:YES];
Uinavigationcontroller must use the category method to implement the following methods to make the keyboard disappear
@interface UINavigationController (DismissKeyboard)- (BOOL)disablesAutomaticKeyboardDismissal;@end@implementation UINavigationController (DismissKeyboard)- (BOOL)disablesAutomaticKeyboardDismissal{ return NO;}@end
3. About delegate in nsurlconnection, the following is a description on the official website:
Note: During a download the connection maintains a strong reference to the delegate. It releases that strong reference when the connection finishes loading, fails, or is canceled.
That is to say, Delegate will be owned by nsurlconnection. The following code can also be used in non-arc scenarios.
// Creates the handler objectmyhandlerclass * Handler = [[myhandlerclass alloc] init]; // creates the connection with handler as an autorelsponobject [[nsurlconnection alloc] initwithrequest: Request delegate: [handler autorelease]; or // creates the handler objectmyhandlerclass * Handler = [[myhandlerclass alloc] init]; // creates the connection with handler [[nsurlconnection alloc] initwithrequest: request delegate: Handler]; // releases handler object [handler release];
The nsurlconnection callback method in myhandlerclass will also be released.
In the case of arc, the Code is as follows:
//creates the handler objectMyHandlerClass *handler = [[MyHandlerClass alloc] init]; //creates the connection with handler[[NSURLConnection alloc] initWithRequest:request delegate:handler];
4. If category is used in the static library, add-all_load or-force_load to the other link when referencing the library.
5. If the project contains the C/C ++ source code, you must note when writing the project prefix. PCH. If you write the following code, the compilation will fail:
#ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h>#endif#import "AppDelegate.h"
The modification method is as follows:
#ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h>#import "AppDelegate.h"#endif
Because this is a pre-compiled header file that is global and all source files are visible to it, it will also be introduced in the C/C ++ source code, if you reference the source code of objective_c in the C/C ++ source code, an error will occur.
6. addsubview of uiview: Method B. If parameter B is the same pointer, no matter how many times it is called, its subview has only one B object. The test environment is ios6. Remember that ios3 does not seem to have this restriction.
7. The precision of the integer part that nsnumber can represent is only 15 digits, which is actually the precision of double. If you need higher precision, use nsdecimalnumber.
8. uitableview:
A. Do not call the-(cgfloat) tableview :( uitableview *) tableview heightforrowatindexpath :( nsindexpath *) indexpath Method
-(Nsindexpath *) indexpathforcell :( uitableviewcell *) cell, which will cause loop calls.
9. Send the crash log to your mailbox
void uncaughtExceptionHandler(NSException *exception) { NSLog(@"CRASH: %@", exception); NSLog(@"Stack Trace: %@", [exception callStackSymbols]); // Internal or email error reporting}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); // Normal launch stuff}
10. When mkannotation is added to mkmapview, The coord value range of mkannotation should be (-180,180). If mkannotation is exceeded, the value cannot be successfully added. The number of annotations arrays in mkmapview is not affected.
11. When using arrays, you must first check whether the index exceeds the array size, otherwise it is easy to crash.
12. Use the weak type to declare delegate. Otherwise, it is easy to use memory leak.
13. Do not use the nsmanagedobject pair as a model library. Do not do this even if the data structure is the same. For example, if ui a shows the query results and ui B deletes the database, it is a tragedy to return to UI.
14. cftyperef does not have the concept of arc, so you need to manage the memory by yourself. When a cftyperef is returned in a method, you must release the memory. Otherwise, the memory leak exists. there are two solutions: one is to return cftyperef in the method surface, the other is to change the value returned by the method to the objc type, so that auto release is supported.
15. Implement private methods in the category method, such as-(void) viewdidappear :( bool) animated, and then in pushviewcontroller
When performing the animation, the unbalanced callto begin/end appearance transitions error will occur.
16. do not perform operations on the subview of uiwindow during animation. I performed show/hide/show on the HUD IN THE viewdidload of VC when pushviewcontroller: VC. The result is not displayed in the HUD.
17. In the development of uitableviewcontroller, uitableview uitableviewdelegate and uitableviewdatasource must be implemented using a separate class, which can reduce the burden on viewcontroller. In uiviewcontroller, message events are processed. In uitableview's uitableviewdatasource, do not specify what is displayed on the first line, what is displayed on the second line, and what needs to be controlled by the data source, that is, it should be displayed based on the data source type.
18. Be careful about the reuse mechanism. For example, uitableviewcell may be a reuse mechanism. Therefore, when using uitableviewcell, you must resume initialization and reuse.
19. Do not hesitate to delete unnecessary code.
20. if the project depends on two libraries, one must be added to the other link flags and the other must be a C/C ++ library, then you need to add a-licucore to solve the problem.
21. Pay attention to data security. encryption is required whether in nsuserdefault or SQLite; otherwise, plaintext is used. Nsuserdefault is actually a plist file. If it runs on the simulator, the path is :~ /Library/Application Support/iPhone
Simulator/4.2/applications/<app_id>/library/preferences :~ /Library/Application Support/mobilesync/backup/<device_id> where <device_id> SQLite is under the document directory.