iOS Development Basics-Fragmentation 9

Source: Internet
Author: User

1: Two methods to delete all records of Nsuserdefaults

// Method One NSString *appdomain =// method Two -(void) resetdefaults {    * defs = [ Nsuserdefaults Standarduserdefaults];     * Dict = [defs dictionaryrepresentation];      for inch dict) {        [defs Removeobjectforkey:key];    }    [Defs synchronize];}

2: Set Global navigation Barbuttonitem

#pragmaMark sets the global navigation Barbuttonitem-(void) Setnavibarbuttonitemimage: (NSString *) imageName andx: (nsinteger) x AndY: (nsinteger) y andw: (Nsinteger) W ANDH: ( Nsinteger) H Andtitle: (NSString *) title Andsel: (SEL) SEL Andlorr: (NSString *) lOr Andtitlecolor: (Uicolor *) color{UIButton*BTN =[UIButton Buttonwithtype:uibuttontypecustom]; Btn.frame=CGRectMake (X,Y,W,H);          [Btn Settitle:title Forstate:uicontrolstatenormal]; if(imagename.length==0&& title.length==0) {              } Else if(imagename.length==0&& title.length!=0) {[btn Setbackgroundcolor:[uicolor Clearcolor]];     [Btn Settitlecolor:color Forstate:uicontrolstatenormal]; }Else if(imagename.length!=0&& title.length==0) {UIImage*image =[UIImage Imagenamed:imagename];     [Btn Setimage:image Forstate:uicontrolstatenormal]; }Else if(imagename.length!=0&& title.length!=0) {UIImage*image =[UIImage Imagenamed:imagename];         [Btn Setbackgroundimage:image Forstate:uicontrolstatenormal];         [Btn Setbackgroundcolor:[uicolor Clearcolor];     [Btn Settitlecolor:color Forstate:uicontrolstatenormal];     } [btn addtarget:self Action:sel forcontrolevents:uicontroleventtouchupinside]; Uibarbuttonitem*BBTN =[[Uibarbuttonitem alloc]initwithcustomview:btn]; if([LOr isequaltostring:@" Left"]) {[Self.navigationitem setleftbarbuttonitem:bbtn]; }Else{[Self.navigationitem setrightbarbuttonitem:bbtn]; } }

3:uitableview Set Section Spacing

when using iOS UITableView, it is often used for its uitableviewstylegrouped grouping multi-section attribute. By default, the spacing between sections is larger and looks uncomfortable when you use this property. You can then configure the spacing for each section of the UITableView by using the following proxy methods. The principle is actually very simple, the display effect of each section spacing is actually the section head and the bottom of the combination. Configuring their spacing is to configure the head and bottom of each section//Section head Spacing-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) Section {return 1;//Section Head Height}  //Section Head View-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) Section {UIView*view=[[uiview Alloc] Initwithframe:cgrectmake (0,0, the,1)]; View.backgroundcolor=[Uicolor Clearcolor]; return[view Autorelease]; }  //Section Bottom Spacing-(CGFloat) TableView: (UITableView *) TableView heightforfooterinsection: (nsinteger) Section {return 1; }  //Section Bottom View-(UIView *) TableView: (UITableView *) TableView viewforfooterinsection: (nsinteger) Section {UIView*view=[[uiview Alloc] Initwithframe:cgrectmake (0,0, the,1)]; View.backgroundcolor=[Uicolor Clearcolor]; return[view Autorelease]; } 

4: Resolve issues that Objc_class_$_mbprogresshud cannot reference

  Although the relevant file has been updated with pod, but it is not introduced into the project, to manually reference it (or directly discard pod management of this plug-in, directly into the project source code)  Undefined symbols   architecture i386:   _objc_class_$_mbprogresshud  Span style= "color: #800000;" > ", referenced from  : OBJC -class -ref  in   ViewController.old:symbol (s) not found  for   architecture I386clang:error:linker command failed with exit code  1  (use-v to see invocation) The error here is because you did not reference the associated header file in building phases, so Just add the corresponding. m file to the building phase. 

5:ios7 using Svpulltorefresh dropdown to refresh the navigation bar position error

iOS7 use Svpulltorefresh dropdown to refresh the navigation bar position error; After a drop-down refresh, the first column of TableView will go below the navigation bar; fix: Add the following code/** * drop-down refresh adds one;*/ //fix drop-down Refresh location error code startif([Self respondstoselector: @selector (automaticallyadjustsscrollviewinsets)]) { Self.automaticallyadjustsscrollviewinsets=NO; Uiedgeinsets insets=Self.tableView.contentInset; Insets.top= Self.navigationController.navigationBar.bounds.size.height +[UIApplication sharedapplication].statusbarframe.size.height; Self.tableView.contentInset=insets; Self.tableView.scrollIndicatorInsets=insets;}//fix drop-down refresh location error code end__block Rootviewcontroller*bself =Self ; [Self.tableview Addpulltorefreshwithactionhandler:^{[bself addrows];}]; /** * Pull to last load more, add one;*/[Self.tableview Addinfinitescrollingwithactionhandler:^{[bself addmorerow];}];

6: When you change the layout to update the effect

CGRect headframe=self.headerview.frame;headframe.size.height= headframe;[ Self.headerview Setneedslayout]; [Self.headerview layoutifneeded];

7: Add a Picture button to the right of the Uitextfield (Rightview)

UIButton *addcommentbtn=[[uibutton Alloc]initwithframe:cgrectmake (00, Inputtextviewheight)]; [Addcommentbtn setimage:[uiimage imagenamed:@ "textvieweditnormal"] forstate: UIControlStateNormal]; [Addcommentbtn addtarget:self Action: @selector (addcommentaction) forcontrolevents:uicontroleventtouchupinside];_ Inputtextview.rightview=addcommentbtn;_inputtextview.rightviewmode=uitextfieldviewmodealways;

8:nslog Output Format Collection

• %@ Object ·%d,%i integers ·%u no-character shaping ·%f floating Point/Double Word ·%x,%X binary integers ·%o octal integers ·%zu size_t%P-pointer ·%e floating Point/double Word (scientific calculation) ·%g floating Point/Double Word ·%s C string ·%.*s Pascal string ·%C character ·%C Unichar%LLD 64-bit long Integer (Long Long) •%llu 64-bit long integer without character%LF 64-bit double word

9: Set the rendering mode of the UIImage: Uiimage.renderingmode

set the rendering mode for UIImage: Uiimage.renderingmode Coloring (Tint Color) is one of the iOS7 interfaces. Set the rendering mode of the UIImage: Uiimage.renderingmode A significant change, you can set a UIImage whether to use the tint Color of the current view when rendering. UIImage added a read-only property: Renderingmode, corresponding to a new method: Imagewithrenderingmode:, It uses the Uiimagerenderingmode enumeration value to set the Renderingmode property of the picture. The enumeration contains the following values:1Uiimagerenderingmodeautomatic//automatically adjusts the rendering mode based on the environment in which the picture is used and the drawing context in which it is located.     2Uiimagerenderingmodealwaysoriginal//always draw the original state of the picture without using tint Color.     3Uiimagerenderingmodealwaystemplate//always draw a picture based on tint color, ignoring the color information of the picture. the default value of the Renderingmode property is Uiimagerenderingmodeautomatic, which is whether uiimage uses tint color depending on where it is displayed. UIImage*img = [UIImage imagenamed:@"MyImage"]; IMG =[img imagewithrenderingmode:uiimagerenderingmodealwaystemplate]; use scene (add Item,item in toolbar to use the background image, the hue will appear blue, If you want to make the original hue of the picture, you want to modify the rendering of the picture because it is currently rendered as a text tone): @property (weak, nonatomic) Iboutlet Uibarbuttonitem*Mycollectionitem; UIImage*collectionitemimage=[uiimage imagenamed:@"Bottomcollectionnormal"];collectionitemimage=[Collectionitemimage Imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];self.mycollectionitem.image =collectionitemimage;

10:navigationcontroller the current page is hidden after the jump back page is also hidden

Current page Hide code: [Self.navigationcontroller Setnavigationbarhidden:yes]; Jump: [Self.navigationcontroller Setnavigationbarhidden:no]; [Self.navigationcontroller Popviewcontrolleranimated:yes];

iOS Development Basics-Fragmentation 9

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.