iphone开发小技巧汇总(1)
- - CSDN博客推荐文章1.iphone之xx_Prefix.pch的作用和用法.
Prefix.pch:扩展名.pch表示"pre-compiled-header",这是一个你工程要用到的 来自于外部框架的头文件列表. xcode将编译这些头到文件,这将减少你在选择Build或Build and Go时编译项目的时间.
pch,系统编译每个.m文件前,都会先import这个文件。这样既节省了你手动添加import的时间,也有助于加速编译.
还有就是可以 在这里面放入宏,在整个工程中都可以用。节省了时间
#ifndef __OPTIMIZE__
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...) {}
#endif
在iphone/mac开发中,unichar是两字节长的char,代表unicode的一个字符。但在xcode中,初始化unichar是个问题。如果像下面这样声明,会有warning"Multi-character character constant"。
unichar a = '国';
这是 因为C语言中两个单引号只能用于char。可以采用直接写文字编码的方式来初始化。
unichar a = 0x0100;
如果有很多个unichar怎么办?一个个去查表太麻烦了。可以采取变通的方法:
unichar a[10];
NSString *aString = @"一二三四五六七八九十";
for (int i = 0; i < 10; i++)
a[i] = [aString characterAtIndex:i];
MFMailComposeViewController *picker = [[MFMailComposeViewControlleralloc] init]; picker.mailComposeDelegate = self; [pickersetSubject:@"I have a pencil for you"]; NSString*databasePathFromApp = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"10.pdf"]; NSData*fileData = [NSDatadataWithContentsOfFile:databasePathFromApp]; [pickeraddAttachmentData:fileData mimeType:@"application/pdf"fileName:@"15.pdf"]; [pickeraddAttachmentData:fileData mimeType:@"application/pdf"fileName:@"16.pdf"]; UIImage*roboPic = [UIImage imageNamed:@"1.png"]; NSData*imageData = UIImageJPEGRepresentation(roboPic, 1); [pickeraddAttachmentData:imageData mimeType:@"image/jpg"fileName:@"1.png"]; NSString*emailBody = @"This is a cool image of a robot Ifound. Check it out!"; [pickersetMessageBody:emailBody isHTML:YES]; [selfpresentModalViewController:picker animated:YES]; [pickerrelease];
UIApplication
对象的 idleTimerDisabled
属性设置为 YES
,就可以禁用自动休眠定时器。NSString *iTunesLink =@"http://itunes.apple.com/us/app/id(产口id号)?mt=8"; [[UIApplication sharedApplication] openURL:[NSURLURLWithString:iTunesLink]];
UILabel *titleText =[[UILabel alloc] initWithFrame: CGRectMake(0, 0,200, 20)]; titleText.backgroundColor =[UIColor clearColor]; [titleText setFont:[UIFontsystemFontOfSize:15.0]]; [titleText setText:@"设置navigationItem标题的字体大小"]; self.navigationItem.titleView=titleText;//titleView [titleText release];