Iphone 优秀的UIKit/Objective-C代码片段
Objective-C iPhone/iPod touch/iPad开发的新功能,但我开始在一行代码中发现许多强大功能,例如:Iphone 优秀的UIKit/Objective-C代码片段,iphone,objective-c,iphone-sdk-3.0,uikit,Iphone,Objective C,Iphone Sdk 3.0,Uikit,Objective-C iPhone/iPod touch/iPad开发的新功能,但我开始在一行代码中发现许多强大功能,例如: [UIApplication sharedApplication].applicationIconBadgeNumber = 10; 它将在你的iphone应用程序上显示一个独特的红色通知徽章,号码为10 请在这里用Objective-C为iPhone/iPod touch/iPad分享您最喜欢的一行或两行仅限公共API使设备振动: AudioServicesPlay
[UIApplication sharedApplication].applicationIconBadgeNumber = 10;
它将在你的iphone应用程序上显示一个独特的红色通知徽章,号码为10
请在这里用Objective-C为iPhone/iPod touch/iPad分享您最喜欢的一行或两行仅限公共API使设备振动:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
使用特定的电话号码打开Messages应用程序:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:123456789"]];
停止响应触摸事件:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
再次开始响应:
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
最后,:
在Safari中打开URL
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com/"]];
隐藏状态栏
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
拨打电话号码(仅限iPhone)
发布苹果邮件
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://mymail@myserver.com"]];
停止响应触摸事件
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
激活触摸事件
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
显示网络活动指示器
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
隐藏网络活动指示器
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
防止iPhone进入睡眠模式
[UIApplication sharedApplication].idleTimerDisabled = YES;
将bool保存为用户默认值
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"Yes Bool"];
将文件从x复制到y
[[NSFileManager defaultManager] copyItemAtPath:x toPath:y error:nil];
显示新视图
[self presentModalViewController:(UIViewController *) animated:YES];
触摸屏法
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {}
获取文档目录
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
加载URL
[MyWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://couleeapps.hostei.com"]]];
获取当前日期和时间:
NSCalendar *gregorian = [NSCalendar currentCalendar];
NSDateComponents *dateComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:[NSDate date]];
自己的枚举类型:
typedef enum {
a = 0, b = 1, c = 2
} enumName;
石英引弧
CGContextRef ctxt = UIGraphicsGetCurrentContext();
CGContextAddArc(ctxt, x, y, radius, startDeg, endDeg);
更改UINavigationView上“后退”按钮上的标题。在推送视图之前,在UINavigationController上使用此代码
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:@"Warning" message:@"too many alerts" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
[alert show]
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
[self.navigationController pushViewController:anotherVC animated:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1]; // fade away over 1 seconds
[aView setAlpha:0];
[UIView commitAnimations];
self.title = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:loginName forKey:kUserLoginName];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:loginName forKey:kUserLoginName];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString*loginName=[默认值stringForKey:kUserLoginName]if ([item respondsToSelector:@selector(activateBOP:)]) {
[item activateBOP:closeBOP];
}
NSLog(@"%s", __PRETTY_FUNCTION__);
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirflg=d", start.latitude, start.longitude, finish.latitude, finish.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
-[UIAlertView show]
返回void
。因此,您正在泄漏内存。哎呀,我试图缩短它,结果把它弄糟了。我会修好的,谢谢!没问题!有时候,我希望所有的方法都返回selfself
;然后,我回想起旧的NeXTSTEP代码,并记住为什么不…:)那时候,几乎一个完整的程序可以放在一行:)它是-setBool:forKey:not-setBool:forKey:所以你可能想修复它。