Use of Arc: ARC does not prevent all memory leaks. There may be memory leaks in the project after using ARC, but the main reasons for these memory leaks are: Block,retain loops, mismanagement of corefoundation objects (usually C structures), and really code not being written well. Reuseidentifier
A common mistake in developing iOS programs is not to set the reuseidentifier correctly for Uitableviewcells, Uicollectionviewcells, and Uitableviewheaderfooterviews.
For best performance, when a cell is returned in the Tableview:cellforrowatindexpath: method, the data source for table view generally reuses the UITableViewCell object. Table view maintains a queue or list of UITableViewCell objects that have been marked for reuse.
What happens if I don't use reuseidentifier? If you do not use Reuseidentifier,table view in your program each time you display a row, you will configure a new cell. This is actually a very resource-intensive operation and can affect the efficiency of the table view scrolling in the program.
Since iOS 7, you may also want headers and footer views, as well as Uicollectionview cell and supplementary views.
In order to use Reuseidentifiers, when a table view requests a new cell, the following method is called in the data source:
static NSString *cellidentifier = @ "Cell";
If the table view maintains a uitableviewcell queue or a cell in the list that is available, a new cell is removed from the queue from the existing cell, or, if not, from the previously registered nib file or class. If there is no cell that can be reused, and the nib file or class is not registered, TableView's Dequeuereusablecellwithidentifier: method returns a nil. Try to set the view to opaque
If the view is opaque, then its opaque property should be set to Yes. Why did you do it? This setting allows the system to draw the view in an optimal way. The opaque property can be set in Interface Builder or code.
Apple's Official document has the following explanation for the opaque attribute:
The provides a hint to the drawing system as to how it should treat the view. If set to YES, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some Drawin G Operations and improve performance. If set to NO, the drawing system composites the view normally and other content. The default value of the IS YES.
(The Opaque property hints at how the system handles view.) If opaque is set to Yes, the drawing system will see view as completely opaque, so the drawing system can optimize some of the drawing operations to improve performance. If set to no, the drawing system handles the view in conjunction with other content. By default, this property is yes. )
If the screen is still, the setting of this opaque property is not a big problem. However, if the view is embedded in scroll view, or is part of a complex animation, setting this property will certainly affect the performance of the program! You can see which view is not set to opaque through the emulator's Debug\color blended layers option. For the performance of the program, set the view as opaque as possible!
I ' m sorry that I long ago coined the term "objects" for this topic because it gets many people to focus on the lesser idea . The big idea is "messaging" –that are what the kernal[sic] of Smalltalk are all about ... The key in making great and growable systems are much more to design how it modules communicate rather than what their int Ernal properties and behaviors should be.
Alan Kay has repeatedly stressed that the core of Smalltalk is not object-oriented, object-oriented is just the lesser ideas, message delivery is the big idea. Generation of dSYM files
The symbol table file. dSYM is actually the file directory that is extracted from the Mach-o file, and the price of the actual data used to save the debug information is DWARF, whose origins can be learned from the Apple employee's article "Apple's" Lazy "DWARF Scheme" one or two.
1. Xcode automatic generation
- Xcode will automatically generate a. dsym file for us when compiling the project or archive, and of course we can prevent it from doing so by changing several of Xcode's build settings.
2. Manual generation
- Another way is to manually extract from the Mach-o file from the command line, such as:
$/applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/dsymutil/users/wangzz/ library/developer/xcode/deriveddata/yourapp-cqvijavqbptjyhbwewgpdmzbmwzk/build/products/debug-iphonesimulator/ Yourapp.app/yourapp-o Yourapp.dsym
This is done through the tool Dsymutil provided by Xcode, from the project compilation result. The Debug symbol table file is extracted from the Mach-o file in the app directory. In fact, Xcode also generates the symbol table file in this way. Compute Crash Symbol table address
Take the following crash stack as an example:
- Thread 0:
- 0 LIBOBJC. A.dylib 0x33f10f60 0x33efe000 + 77664
- 1 Foundation 0x273526ac 0x2734a000 + 34476
- 2 Foundation 0x27355c3e 0x2734a000 + 48190
- 3 UIKit 0x29ef9d1c 0x29bbc000 + 3398940
- 4 UIKit 0x29ef9c9a 0x29bbc000 + 3398810
- 5 UIKit 0x29ef954c 0x29bbc000 + 3396940
- 6 UIKit 0x29c3a16a 0x29bbc000 + 516458
- 7 UIKit 0x29e4b8e6 0x29bbc000 + 2685158
- 8 UIKit 0x29c3a128 0x29bbc000 + 516392
- 9 Your 0x000f0846 0xa2000 + 321606
- Ten UIKit 0x29e90fb2 0x29bbc000 + 2969522
- UIKit 0x29e91076 0x29bbc000 + 2969718
- UIKit 0x29e867cc 0x29bbc000 + 2926540
- UIKit 0x29c9e8ea 0x29bbc000 + 927978
- UIKit 0x29bc8a6a 0x29bbc000 + 51818
- Quartzcore 0x295f0a08 0x295e4000 + 51720
- Quartzcore 0x295ec3e0 0x295e4000 + 33760
- Quartzcore 0x295ec268 0x295e4000 + 33384
- Quartzcore 0x295ebc4c 0x295e4000 + 31820
- Quartzcore 0x295eba50 0x295e4000 + 31312
- Quartzcore 0x295e5928 0x295e4000 + 6440
- Corefoundation 0x266d0d92 0x26604000 + 839058
- Corefoundation 0x266ce44e 0x26604000 + 828494
- Corefoundation 0x266ce856 0x26604000 + 829526
- Corefoundation 0X2661C3BC 0x26604000 + 99260
- Corefoundation 0x2661c1ce 0x26604000 + 98766
- Graphicsservices 0x2da1a0a4 0x2da11000 + 37028
- UIKit 0x29c2a7ac 0x29bbc000 + 452524
- Your 0x0024643a 0xa2000 + 1721402
- Libdyld.dylib 0X34484AAC 0x34483000 + 6828
1, the symbol table stack address calculation method
To resolve the crash location using the symbol table, you need to calculate the corresponding crash stack address in the symbol table. As you can see from line 9th of the above stack, the application crash occurs at run-time address 0x000f0846, where the run-time start address is 0xa2000, and the offset from the start address of the process is at 321606 decimal (corresponding to hexadecimal 0x4e846). Three correspondence relations:
0x000f0846 = 0xa2000 + 0x4e846
The corresponding formula is:
- Run-time Stack address = run-time start address + offset
The start address and crash address in the crash stack are run-time addresses, according to the invariant principle of the virtual memory offset, as long as the starting address of the text segment of the symbol table is provided, plus the offset (here 0x4e846) to get the stack address in the symbol table, namely:
- Symbol table stack address = symbol table start address + offset
Self.navigationItem.leftBarButtonItem = [[Uibarbuttonitem alloc] initwithimage:img style: Uibarbuttonitemstyleplain target:self Action: @selector (Onback:)]; Self.navigationController.interactivePopGestureRecognizer.delegate = (id<uigesturerecognizerdelegate>) Self ;
Adjust the position of the separaline without creating a new cell?
_mytableview.separatorinset = Uiedgeinsetsmake (0, 100, 0, 0);
Hide the Navigationbar when sliding?
Navigationcontroller.hidesbarsonswipe = Yes
The title of the Nav bar return key is gone!
[[Uibarbuttonitem appearance] Setbackbuttontitlepositionadjustment:uioffsetmake (0, -60) forbarmetrics: Uibarmetricsdefault];
Use only one pan gesture in place of the uiswipegesture in each direction?
1-(void) pan: (Uipangesturerecognizer *) Sender 2 {3 typedef ns_enum (Nsuinteger, uipangesturerecognizerdirection) {4 uipangesturerecognizerdirectionundefined, 5 uipangesturerecognizerdirectionup, 6 Uipangesturerecognizerdirectiond Own, 7 Uipangesturerecognizerdirectionleft, 8 uipangesturerecognizerdirectionright 9};10 static UIPANGESTURERECOG Nizerdirection Direction = uipangesturerecognizerdirectionundefined;11 switch (sender.state) {case Uigesturerecogni Zerstatebegan: {if (direction = = uipangesturerecognizerdirectionundefined) {Cgpoint velocity = [ Sender velocityinview:recognizer.view];15 BOOL isverticalgesture = fabs (velocity.y) > Fabs (velocity.x); 16 if (isverticalgesture) {if (velocity.y > 0) {direction = Uipangest Urerecognizerdirectiondown;19} else {direction = Uipangesturerecognizerdirectionup ; 21}22 }23 else {if (velocity.x > 0) {direction = Uipangestu Rerecognizerdirectionright;26} else {direction = Uipangesturerecognizerdirectionle ft;28}29}30}31 break;32}33 case uigesturerecognizerstatechanged: { switch (direction) {uipangesturerecognizerdirectionup: {$ [Self Handleupwa rdsgesture:sender];37 break;38}39 Case Uipangesturerecognizerdirectiondown: {40 [Self handledownwardsgesture:sender];41 break;42}43 case uipangest Urerecognizerdirectionleft: {[Self handleleftgesture:sender];45 break;46}4 7 Case uipangesturerecognizerdirectionright: {handlerightgesture:sender];49 Break;50 }51 default: {break;53}54}55 break;56}57 case UI gesturerecognizerstateended: {direction = uipangesturerecognizerdirectionundefined; break;60}61 default:62 break;63}64}Change the color and position of the Uitextfield placeholder
Inherit Uitextfield, override this method
1-(void) Drawplaceholderinrect: (CGRect) Rect {2 [[Uicolor Bluecolor] setfill];3 [Self.placeholder drawinrect : Rect withFont:self.font linebreakmode:uilinebreakmodetailtruncation Alignment:self.textalignment];4}
Make the Navigationbar transparent, not blurry.
1 [self.navigationbar setbackgroundimage:[uiimage new]2 forbarmetrics:uibarmetricsdefault];3 Self.navigationBar.shadowImage = [UIImage new];4 self.navigationBar.translucent = YES;
StatusBar is lightcontent, results in Uiimagepickercontroller will cause my statusbar style to turn black
1-(void) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Willshowviewcontroller: ( Uiviewcontroller *) Viewcontroller animated: (BOOL) animated2 {3 [[UIApplication sharedapplication] SETSTATUSBARSTYLE:UISTATUSBARSTYLELIGHTCONTENT];4}
Change the color of the small tableview in the cell to another color.
_mtableview.tintcolor = [Uicolor Redcolor];
A Word add pull up refresh? (There's a better mjrefresh you know)
1 Https://github.com/samvermette/SVPullToRefresh2 3 [TableView addpulltorefreshwithactionhandler:^{4//prepend data To DataSource, insert cells at the top of table VIEW5//Call [Tableview.pulltorefreshview stopanimating] when Done6} positio N:svpulltorefreshpositionbottom];
About the run-time
1 unsigned int count; 2//Get attribute list 3 objc_property_t *propertylist = Class_copypropertylist ([self class], &count); 4 for (unsigned int i=0; i<count; i++) {const char *propertyname = "property_getname (Propertylist[i]);" NSLog (@ "Property----=" ">%@", [NSString Stringwithutf8string:propertyname]); 5} 6//Get a list of methods 7 method *methodlist = Class_copymethodlist ([self class], &count); 8 for (unsigned int i; i<count; i++) {Method method = "methodlist[i];" NSLog (@ "Method----=" ">%@", Nsstringfromselector (Method_getname (method))); 9}10//Get a list of member variables Ivar *ivarlist = Class_copyivarlist ([self class], &count); n for (unsigned int i; i <count; i++) {Ivar Myivar = "ivarlist[i];" const char *ivarname = "ivar_getname (Myivar);" NSLog (@ "Ivar----=" ">%@", [NSString Stringwithutf8string:ivarname]); 13}14//Get agreement list __unsafe_unretained Pr Otocol **protocollist = Class_copypRotocollist ([Self class], &count); (unsigned int i; i<count; i++) {protocol *myprotocal = "Proto Collist[i]; " const char *protocolname = "protocol_getname (myprotocal);" NSLog (@ "protocol----=" ">%@", [NSString Stringwithutf8string:protocolname]); 17
Method invocation If an instance method is called with an instance object, the object (that is, the class object) that the instance's Isa pointer points to is manipulated.
If a class method is called, it is manipulated in the object that the ISA pointer to the class object points to (that is, the meta-class object).
- First, the method to invoke is found in the list of cached methods in the corresponding action object, and if found, turn to the corresponding implementation and execution.
- If not found, find the method in the method list in the corresponding action object, and if found, turn to the corresponding implementation
- If not found, go to the object that the parent pointer points to.
- And so on, if the root class hasn't been found yet, turn to intercept call.
- If there is no way to rewrite the interception call, the program error.
The above process brings me the inspiration:
- Overriding the method of the parent class does not overwrite the parent class, except that the method is found in the current class object and will not be found in the parent class.
- If you want to invoke the implementation of the parent class of a method that has already been overridden, simply use the Super compiler identifier, which skips the process of finding a method in the current class object at run time.
iOS Development-Development summary