Remove warnings, call, send messages, jump between applications, print sandbox path, string name conversion method, package navigation controller code, etc.

Source: Internet
Author: User

To read a value from a preference setting:

Phone Code:

Send Message code:

To print the sandbox path code:

Jump code between applications:

Skip to the Apple Store code:

To remove the warning code:

Code that is converted to a relative method based on the string name:

#import "SZMSettingsCell.h"@implementationSzmsettingscell//Select a different cell type+ (Uitableviewcellstyle) cellstylewithdict: (Nsdictionary *) dict{Uitableviewcellstyle cellstyle=Uitableviewcellstyledefault; if([dict[@"CellStyle"]isequaltostring:@"Uitableviewcellstylesubtitle"]) {CellStyle=Uitableviewcellstylesubtitle; }Else if([dict[@"CellStyle"]isequaltostring:@"UITableViewCellStyleValue1"]) {CellStyle=UITableViewCellStyleValue1; }Else if([dict[@"CellStyle"]isequaltostring:@"UITableViewCellStyleValue2"]) {CellStyle=UITableViewCellStyleValue2; }    returnCellStyle; }+ (Instancetype) Settingscellwithtableview: (UITableView *) TableView withdict: (Nsdictionary *) dict{StaticNSString *id =@"ID"; Szmsettingscell*cell =[TableView Dequeuereusablecellwithidentifier:id]; if(Cell = =Nil) {Cell=[[Szmsettingscell alloc]initwithstyle:[self cellstylewithdict:dict] reuseidentifier:id]; }    returncell;}- (void) SetItem: (Nsdictionary *) item{_item=item; //set Text to cellSelf.textLabel.text = item[@"title"]; //set a picture for cell    if(item[@"icon"]) {self.imageView.image= [UIImage imagenamed:item[@"icon"]]; }    //give the cell more information    if(item[@"Details"] && [item[@"Details"] length] >0) {Self.detailTextLabel.text= item[@"Details"]; //determine if the cell's detail text needs to change to red        if(item[@"ishighlighted"]) {Self.detailTextLabel.textColor=[Uicolor Redcolor]; }    }        //determine if the details in the current cell are set in preferences    if(item[@"Detailskeyname"]) {        //read stored content from PreferencesNsuserdefaults *defaults =[Nsuserdefaults Standarduserdefaults]; NSString*text = [Defaults objectforkey:item[@"Detailskeyname"]]; //If the stored content is not empty        if(text) {Self.detailTextLabel.text=text; }    }        //set the Accessoryview on the right    if(item[@"Accessory"]) {        //create the corresponding class based on the string in the configuration file (item[@ "accessory"] in the corresponding string in the plist file)Class ACCESSORYCALSS = nsclassfromstring (item[@"Accessory"]); //Create objects of this type        IDobj =[[Accessorycalss alloc]init]; if([obj Iskindofclass:[uiimageviewclass]]) {            //represents a picture frameUiimageview *imgview = (Uiimageview *) obj; Imgview.image= [UIImage imagenamed:item[@"Accessoryimage"]]; //Resize the picture box to the same size as the picture[Imgview SizeToFit]; }                //set the Accessoryview of the cell to the dynamic creation of this typeSelf.accessoryview =obj; //to determine if it is a switch, register a valuechange event        if([obj Iskindofclass:[uiswitchclass]]) {Uiswitch*switcher = (Uiswitch *) obj;                        [Switcher addtarget:self Action: @selector (swithcvaluechanged:) forcontrolevents:uicontroleventvaluechanged]; //read the value of the switch from the preferences and set theNsuserdefaults *userdefault =[Nsuserdefaults Standarduserdefaults]; //ReadSwitcher.on = [Userdefault boolforkey:self.item[@"KeyName"]]; }            }}- (void) swithcvaluechanged: (Uiswitch *) sender{//get the status of the switch//Save switch status to PreferencesNsuserdefaults *userdefu =[Nsuserdefaults Standarduserdefaults]; [Userdefu setBool:sender.isOn forkey:self.item[@"KeyName"]];    [Userdefu Synchronize]; }- (void) SetTime: (NSString *) str{Self.detailTextLabel.text=str; //Give time to preferences to recordNsuserdefaults *userdefu =[Nsuserdefaults Standarduserdefaults]; [Userdefu setobject:str forkey:self.item[@"Detailskeyname"]]; [Userdefu synchronize];}

To package a controller into the code of the Navigation controller:

Remove warnings, call, send messages, jump between applications, print sandbox path, string name conversion method, package navigation controller code, etc.

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.