Objective C 显示/隐藏iPhone状态栏

//Hide
[UIApplication sharedApplication].statusBarHidden = YES;

//Show
[UIApplication sharedApplication].statusBarHidden = NO;

Objective C iphone:视图之间的转换

// get the view that's currently showing
 UIView *currentView = self.view;
 // get the the underlying UIWindow, or the view containing the current view view
 UIView *theWindow = [currentView superview];
 
 // remove the current view and replace with myView1
 [currentView removeFromSuperview];
 [theWindow addSubview:view1];
 
 // set up an animation for the transition between the views
 CATransition *animation = [CATransition animation];
 [animation setDuration:0.5];
 [animation setType:kCATransitionPush];
 [animation setSubtype:kCATransitionFromRight];
 [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
 
 [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];*/

Objective C iphone HTTP请求

//prepar request
	NSString *urlString = [NSString stringWithFormat:@"http://urlToSend.com"];
	NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
	[request setURL:[NSURL URLWithString:urlString]];
	[request setHTTPMethod:@"POST"];
	
        //set headers
	NSString *contentType = [NSString stringWithFormat:@"text/xml"];
	[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

	//create the body
	NSMutableData *postBody = [NSMutableData data];
	[postBody appendData:[[NSString stringWithFormat:@"<xml>"] dataUsingEncoding:NSUTF8StringEncoding]];
	[postBody appendData:[[NSString stringWithFormat:@"<yourcode/>"] dataUsingEncoding:NSUTF8StringEncoding]];
	[postBody appendData:[[NSString stringWithFormat:@"</xml>"] dataUsingEncoding:NSUTF8StringEncoding]];
	
        //post
	[request setHTTPBody:postBody];
	
	//get response
	NSHTTPURLResponse* urlResponse = nil;  
	NSError *error = [[NSError alloc] init];  
	NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];  
	NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
	NSLog(@"Response Code: %d", [urlResponse statusCode]);
	if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
		NSLog(@"Response: %@", result);
	        
                //here you get the response

	}

Objective C 重复的Xcode项目

1. Copy/rename the folder into new name
   2. Get inside the new folder and rename the .pch and .xcodeproj files
   3. Delete the build folder
   4. Open .xcodeproj file in text editor, like TextMate or TextWrangler. That’s actually a folder, which contains 4 files (you can also right-click and do Show package contents, which will reveal the files)
   5. Open project.pbxproj in text editor and replace all instances of the old name with the new name
   6. Load the project file in XCode, do Build/Clean all targets

Objective C 获取iPhone应用程序版本号

NSString*	version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

Objective C iPhone和Cocoa上的日期格式

//Format Date
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat: @"yyyy-MM-dd HH:mm:ss zzz"]; // 2009-02-01 19:50:41 PST
NSString *dateString = [dateFormat stringFromDate: [scoreData objectForKey: @"date"]];

Objective C 在Safari中打开URL

NSURL *url = [ [ NSURL alloc ] initWithString: @"http://www.cnn.com" ];
[[UIApplication sharedApplication] openURL:url];