A summary of some of the problems with iOS development

Source: Internet
Author: User
Tags local time
iphone Development Navbar+tarbar
1 Change navbar color: Select the Tint property of navigation Bar. Select the color.

2 Hide "Back" button: Self.navigationItem.hidesBackButton = YES;

3 Hide "NavBar": Self.navigationController.navigationBarHidden = YES;

4 can be created without mainwindow.xib navigation. Customize on each view.

You need to add the following code to each control page to hide the Nav:
-(void) Viewwillappear: (BOOL) animated
{
Self.navigationController.navigationBarHidden = yes;//display "NavBar"
}
Then add navigation Bar xib yourself on each control page. Add the desired Barbuttonitem button.


5 page Jump Hide TarBar:
Homedetailviewcontroller *detailview = [[Homedetailviewcontroller alloc] initwithnibname:@ "HomeDetailView" bundle: NIL];
detailview.hidesbottombarwhenpushed = yes;//Hide TarBar
[Self.navigationcontroller Pushviewcontroller:detailview Animated:yes];
[DetailView release];

6 page return:
[Self.navigationcontroller Popviewcontrolleranimated:yes];

7 The default check Tabbar is the first view:
tabbarcontroller.selectedindex= 0;


Other:
8 The latitude and longitude of the two places are known to calculate the distance between:
Map shows current position:
Mapview.showsuserlocation=yes;
Cllocationmanager *locationmanager = [[Cllocationmanager alloc] init];//Create location Manager
locationmanager.delegate=self;//Settings Agent
LOCATIONMANAGER.DESIREDACCURACY=KCLLOCATIONACCURACYBEST;//Specifies the desired precision level as the best precision
locationmanager.distancefilter=1000.0f;//set the distance filter to send updates for any move
[Locationmanager startupdatinglocation];//Boot location Manager
Mkcoordinatespan Thespan;
The smaller the map, the more accurate the range.
thespan.latitudedelta=0.05;
thespan.longitudedelta=0.05;
Mkcoordinateregion theregion;
Theregion.center=[[locationmanager location] coordinate];
Theregion.span=thespan;
[Mapview setregion:theregion];
[Locationmanager release];

Mkuserlocation *usrloc=mapview.userlocation;
Cllocationcoordinate2d usrcoordinate=usrloc.location.coordinate;
NSLog (@ "la==%f lo==%f", usrcoordinate.latitude,usrcoordinate.longitude);

The latitude and longitude of two points are known to calculate the distance between two places:
Cllocation *location1 = [[[Cllocation alloc] InitWithLatitude:usrCoordinate.latitude Longitude: Usrcoordinate.longitude] autorelease];
Cllocation *location2 = [[[Cllocation alloc] initwithlatitude:36.676445 longitude:117.106793] autorelease];
NSLog (@ "juli====%.0f km", [Location1 Distancefromlocation:location2]);//4502


9 after the decimal point two digits (rounded), output:
NSLog (@ "%.02f km", 4478.442312);

10 Call to call API:
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "tel://10010"];
When you make a call this way, when the user ends the call, the iphone interface stays on the phone interface.
You can use the following method to automatically return the user to the application after you end the call:
Uiwebview*callwebview =[[uiwebview alloc] init];
Nsurl *telurl =[nsurl urlwithstring:@ "tel:10086"];//looks like tel://or Tel: All right
[Callwebview loadrequest:[nsurlrequest Requestwithurl:telurl]];
Remember to add to view
[Self.view Addsubview:callwebview];

11 Call SMS Send SMS:
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "sms://15315310992"];

12 Call self-browser safari
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "http://www.baidu.com"];

13 Open Another program in one program:
First: plist add URL types point open inside Item0 add urlschemes open Item0 input Sinaweibo
And then where it needs to be invoked: [[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ ' sinaweibo://* ']];

Https://itunes.apple.com/cn/app/qq-2012/id444934666?mt=8

14 Double Quote escape:
Double quotes with \ "

15 Set Button Press to change the picture to loosen or the original image
[Danxuan setimage:[uiimage imagenamed:@ "Exercise_option_n.png"] forstate:uicontrolstatenormal];
This is the set of pressed pictures, loosen up is the picture above
[Danxuan setimage:[uiimage imagenamed:@ "Exercise_option_s.png"] forstate:uicontroleventtouchdragoutside];

The Uialertview has 3 buttons, directly added directly to other, separated by commas
Uialertview *alerduibiviewall = [[Uialertview alloc] initwithtitle:@ "whether to add a contrast. "Message:nil delegate:self cancelbuttontitle:@" Cancel "otherbuttontitles:@" Add "," delete this item ", nil];
[Alerduibiviewall show];
Ways to get Alertview
-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) Buttonindex
{
if (Buttonindex ==1)///contrast:
{
}
if (Buttonindex ==2)//delete:
{
}
}

Array-Related:
17 determine if an element exists in the array:
BOOL isvalue=[keyarray containsobject:@ "AAA"];
18.1 separate the strings by commas and save them to the array:
Nsarray *keyarray=[[nsarray alloc] init];
keyarray=[@ "Wax gourd, watermelon, pumpkin, balsam pear, loofah" componentsseparatedbystring:@ ","];

18.2 take out the array and spell it as a comma-separated string:
NSString *n=[keyarray componentsjoinedbystring:@ ","];

18.3 Nsmutablearray into Nsarray
Nsarray *phonea=[[nsarray alloc] init];
Nsmutablearray *phonearrayss=[[nsmutablearray alloc] init];
Phonea=[phonearrayss Mutablecopy];

19 Get local time (uppercase HH get 24-hour system)
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[Formatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss"];
NSString *timestr=[formatter stringfromdate: [NSDate Date]];

UITableView Some properties:
tableview.bounces=no//Prohibit drag
Tableview.separatorstyle = uitableviewcellseparatorstylenone;//Remove Border
[Cellview setselectionstyle:uitableviewcellselectionstylenone];//prohibit triggering click on a line
To achieve the selected effect of a row (click on a row to change color, loosen or just change the color, click on the other line the color disappears):
[Cellview Setbackgroundcolor:[uicolor Clearcolor]];
Cellview.selectedbackgroundview = [[[UIView alloc] initWithFrame:cellView.frame] autorelease];
Uiimageview *ia1=[[uiimageview alloc]initwithframe:cgrectmake (0, 0, 280, 170)];
Ia1.image=[uiimage imagenamed:@ "Ts_bg01.png"];
Cellview.backgroundview=ia1;

Uiimageview *ia2=[[uiimageview alloc]initwithframe:cgrectmake (0, 0, 280, 170)];
Ia2.image=[uiimage imagenamed:@ "Ts_bg02.png"];
CELLVIEW.SELECTEDBACKGROUNDVIEW=IA2;

21 Notice Nsnotificationcenter Related:
21.1 Definition Notices:
Nsnotificationcenter *NCN = [Nsnotificationcenter defaultcenter];
[NCN addobserver:self selector: @selector (duibishow:) name:@ "Duibibutton" object:nil];

21.2 define the method of notification invocation:
-(void) Duibishow: (nsnotification*) notification
{
Nsmutablearray *array = [notification object];//through this gets to the passed object
}

21.3 Call Notification:
[[Nsnotificationcenter Defaultcenter] postnotificationname:@ "Duibibutton" Object:passduibiarray];

21.4 Remove the notification that name is Duibibutton:
[[Nsnotificationcenter Defaultcenter] removeobserver:self name:@ "Duibibutton" object:nil];

21.5 remove this viewcontroll page so notice:
[[Nsnotificationcenter Defaultcenter] removeobserver:self];

Uiscrollview Property:
Tracking//When the touch has not been dragged when the value is yes, otherwise no
Zoombouncing//When the content is enlarged to the maximum or minimum value is yes, otherwise NO
zooming//The value is yes when zooming, otherwise NO
decelerating//When scrolling, the finger is released but continues to scroll. This time is yes, other times is NO
Decelerationrate//Set the deceleration rate after finger release
Maximumzoomscale//A floating-point number indicating the maximum multiple
Minimumzoomscale//A floating-point number indicating the minimum number of times that can be shrunk
Pagingenabled//Duty is yes automatically scrolls to the Subview boundary. Default is No
scrollenabled//Decide whether you can scroll
Sview.contentsize = Cgsizemake (320*5,372);//scrolling range

Delayscontenttouches//Is a Boolean, when the value is yes, the user touches the start, scroll view to delay a moment to see if the user has intent to scroll. If scrolling, then catch Touch-down event, otherwise it will not capture. If the value is no, when the user touches, scroll view immediately triggers the TouchesShouldBegin:withEvent:inContentView: Yes, by default

Cancancelcontenttouches//Duty is yes when the user touches and then does not move within a certain period of time, ScrollView sends tracking events, and then the user moves the finger enough to trigger the scrolling event, and this time, ScrollView sent Touchescancelled:withevent: to Subview, then Scroview started scrolling. If the value is No,scrollview send tracking events, even if the user moves the finger, ScrollView will not scroll.

Contentsize//Inside content size, that is, can scroll the size, the default is 0, no scrolling effect.
Display horizontal scroll bar when showshorizontalscrollindicator//scrolling
Display vertical scroll bar when showsverticalscrollindicator//scrolling
Bounces//The default is yes, that is, scrolling over the border will bounce back with a rebound effect. If it is NO, then scrolling to the boundary will stop at once.
Bounceszoom//And bounces are similar, the difference is that this effect is reflected in the zoom, if the zoom exceeds the maximum zoom, then the rebound effect, if NO, the maximum or the smallest time to stop immediately.

directionallockenabled//The default is NO, you can move in both vertical and horizontal directions simultaneously. If the value is yes, if the first is vertical or horizontal movement, then the next one will lock the scroll in the other direction. If you start out in a diagonal direction, you won't block a direction
Indicatorstyle//scroll bar style, basically just set the color. Total 3 colors: default, Black, white
Scrollindicatorinsets//Set the scroll bar position

Uilabel Self Adaptation:
Uilabel *requestlabel = [[Uilabel alloc] Initwithframe:cgrectmake (titletypelabel.frame.origin.y+ TITLETYPELABEL.FRAME.SIZE.HEIGHT+20, 280, 20)];
Uifont *font2 = [Uifont systemfontofsize:14];
[Requestlabel Setfont:font2];
[Requestlabel setnumberoflines:0];
[Requestlabel Setbackgroundcolor:[uicolor Clearcolor]];
NSString *text2 = [NSString stringwithformat:@ "Requirements:%@", req];
Cgsize size2 = [Text2 sizewithfont:font2 constrainedtosize:cgsizemake (280.0f, 200.0f) Linebreakmode: Uilinebreakmodewordwrap];
CGRect rect2 = requestlabel.frame;
Rect2.size = Size2;
[Requestlabel Setframe:rect2];
[Requestlabel SETTEXT:TEXT2];
[Littlescrollview Addsubview:requestlabel];

24 The Uialertview that pops up when data is processed, put a rotating uiactivityindicatorview above. When processing the data uialertview automatically disappears.
Loginalerview = [[Uialertview alloc]
Initwithtitle:nil message:@ "Please wait patiently ⋯⋯\n\n in the data download"
Delegate:nil Cancelbuttontitle:nil
Otherbuttontitles:nil];
uiactivityindicatorview* progressind = [[Uiactivityindicatorview alloc] Initwithframe:cgrectmake (120, 70, 40, 40)];
[Progressind startanimating];
Progressind.activityindicatorviewstyle = Uiactivityindicatorviewstylewhitelarge;
[Loginalerview Addsubview:progressind];
[Loginalerview show];

Uialertview automatically disappears (and the same effect as clicking the Cancel button is invoked when needed):
[Loginalerview Dismisswithclickedbuttonindex:[loginalerview Cancelbuttonindex] animated:yes];

25 Removing spaces from nsstring
Nscharacterset *whitespace = [Nscharacterset whitespaceandnewlinecharacterset];
NSString * username = [Musernamefield stringvalue];
Username = [username stringbytrimmingcharactersinset:whitespace];

26 Animate: Display a series of static images one after another:
Nsarray *myimages = [Nsarray arraywithobjects: [uiimage imagenamed:@ "Myimage1.png"], [UIImage imageNamed:@] Myimage2.png "], [uiimage imagenamed:@" Myimage3.png "], [uiimage imagenamed:@" Myimage4.gif "], nil];
Uiimageview *myanimatedview = [Uiimageview alloc];
[Myanimatedview initwithframe:[self bounds]];
Myanimatedview.animationimages = MyImages; Animationimages property returns an array of animated pictures
Myanimatedview.animationduration = 0.25; The time spent browsing the entire picture once
Myanimatedview.animationrepeatcount = 0; 0 = Loops Forever Animation repeat number
[Myanimatedview startanimating];
[Self addsubview:myanimatedview];
[Myanimatedview release];

UIWebView Full Display HTML:
Define global variables UIWebView *content; Join Agent Uiwebviewdelegate;
Instantiated:
Content = [[UIWebView alloc] Initwithframe:cgrectmake (0, 60, 570, 540)];
self.content.delegate=self;
[Self.content Setuserinteractionenabled:no]; Remove scroll bars and prevent scrolling
[Content Setbackgroundcolor:[uicolor Clearcolor]];
[Self.noticescroll addsubview:content];

NSString *htmlid = [NSString stringwithformat:@ "<div id= ' foo ' >%@</div>", caseinfos.content];// Add the foo tag to your HTML to calculate the length of the HTML.
[Self.content loadhtmlstring:[nsstring Stringwithformat:htmlid] Baseurl:[nsurl fileurlwithpath:[[nsbundle Mainbundle] Bundlepath]];

Called when the WebView load completes:
-(void) Webviewdidfinishload: (UIWebView *) WebView
{
Get the height of the HTML:
NSString *output = [webview stringbyevaluatingjavascriptfromstring:@ document.getElementById (\ "foo\"). OffsetHeight ;"];
[Self.content Setframe:cgrectmake (0,60, 570,[output intvalue]+30)];//settings UIWebView
Self.noticeScroll.contentSize = Cgsizemake (570, content.frame.origin.y+content.frame.size.height); Set the scrolling range for Uiscrollview
}

28 Determine if there is a network:
Import the file in the attachment, and then introduce #import "IsNetworking.h" on the page that needs to be judged;
Isnet.zip (2 K) Download times: 35
The place to judge:
isnetworking *isnetwork = [[Isnetworking alloc] init];
BOOL Isnets=[isnetwork isnetworkreachable];
if (isnets==no) {//No network}
else{//has network}

29 SQL statements that are frequently used in development:
INSERT OR REPLACE into Phoneinfo (id,logo,name) VALUES (%d, '%@ ', '%@ ')//Add
Update mobphoneinfo id=%d,logo= '%@ ', name= '%@ '//Modify
Delete from Phoneinfo//delete all data in a table
Delete from Phoneinfo Where id=2//delete id=2 data in the table

SELECT * from phoneinfo sequence by id DESC//Query All data in order of ID from large to small
SELECT ID from Phoneinfo ORDER by ID desc LIMIT 0,1//query maximum ID
SELECT * from Phoneinfo where name like ' Samsung '//query all data for name Samsung
SELECT * from Phoneinfo where NetFlow like '% percent Internet% '//query NetFlow contains all data in ' Internet '
SELECT count (Name) num from phoneinfo where id=2//query id=2 total data
SELECT * from Phoneinfo ORDER by RANDOM () limit 3//query 3 random data

30 String Related:
30.1 Append characters:
nsmutablestring *string = [[Nsmutablestring alloc] init];
string=@ "Hello";
[String appendformat:@ "China"];

30.2 string Replacement: Replace all < in info with #
NSString *stroneintro=[info Stringby
Related Article

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.