iOS Development Basics-Fragmentation 9

Source: Internet
Author: User

1: Two methods to delete all records of Nsuserdefaults

Method one NSString *appdomain = [[NSBundle mainbundle] bundleidentifier]; [[Nsuserdefaults Standarduserdefaults] removepersistentdomainforname:appdomain]; Method two-(void) Resetdefaults {    nsuserdefaults * defs = [nsuserdefaults standarduserdefaults];    Nsdictionary * dict = [defs dictionaryrepresentation];    For (ID key in dict) {        [defs Removeobjectforkey:key];    }    [Defs synchronize];}

2: Set Global navigation Barbuttonitem

#pragma mark set 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//section head spacing of each section-(cgfloat) TableView: (UITableView *) TableView heightforheaderinsection: ( Nsinteger) Section {return 1;//section head height}//section head View-(UIView *) TableView: (UITableView *) TableView viewfor      Headerinsection: (Nsinteger) Section {UIView *view=[[uiview alloc] Initwithframe:cgrectmake (0, 0, 320, 1)];      View.backgroundcolor = [Uicolor Clearcolor];  return [view Autorelease];  }//section Bottom Pitch-(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, 320, 1)];      View.backgroundcolor = [Uicolor Clearcolor]; return [View AutorelEase];  }

4: Resolve issues that Objc_class_$_mbprogresshud cannot reference

Although the relevant files have been updated with pod, but it is not introduced into the project, to manually reference it (or directly discard pod management This plug-in, directly into the project source code) Undefined symbols for architecture i386:  " _objc_class_$_mbprogresshud ", 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) Here's the error because you're in building phases There is no reference to the associated header file, so you only need to add the corresponding. m file in 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 the refresh, the first column of TableView will go to the bottom of the navigation bar; fix: Add the following code/** * drop-down refresh to add  one; *//fix drop Refresh location error Code start if ([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 position 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=200;self.headerview.frame = 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 (0, 0, 40,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 integer%u no-character shaping%f floating-point/double-word%x,%x binary integer%o Octal integer%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%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: 1 uiimagerenderingmodeautomatic  //  automatically adjusts the rendering mode based on the environment in which the picture is used and the drawing context in which it is located.    2 uiimagerenderingmodealwaysoriginal   //  always draws the original state of the picture without using Tint color.    3 uiimagerenderingmodealwaystemplate   //  always draw pictures 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 scenes (add Item,item in toolbar to use the background map, there will be shades of blue, If you want to be the original color of the picture, then you want to modify the rendering of the picture, because it is currently rendered into text tones): @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.