1.快速打开当前工程的某个文件 —— shift+command+o
1.某一类库方法中有关:
@required 这个是必须的
@optional 这个是可选的
2.在info里面添加一个语言
Localizations ——》Language
然后在Supporting Files文件夹里的--》
InfoPlist.strings(english)里添加:
CFBundleDisplayName = "English Name";
InfoPlist.strings(chinese)里添加:
CFBundleDisplayName = "中文名称";
则即为此应用的中文名和英文名
3.添加程序启动图片:直接加入并命名为:“defualt.png”即默认图片。
添加应用logo:直接加入图片并命名为:“icon.png”
4.给顶部navigation设置风格,要写在viewdidload方法里,在init方法不行
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];
if (self) {
self.tabBarItem.title =NSLocalizedString(@"First",@"First");
self.tabBarItem.image = [UIImageimageNamed:@"first"];
self.navigationItem.title =NSLocalizedString(@"Schedule",@"Schedule");
self.navigationItem.leftBarButtonItem = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdittarget:selfaction:@selector(edit:)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAddtarget:selfaction:@selector(add:)];
self.navigationController.navigationBar.barStyle =UIBarStyleBlackOpaque;
}
returnself;
}
推进下一视图:
[[selfnavigationController]pushViewController:view2animated:YES];
[selfpresentModalViewController:navanimated:YES];
5.可变数组使用前必须先申请空间,不建议直接赋值,否则会出现诡异错误!
6.二级类给一级类传值可用两种方法
【1】直接调用按照子视图所在类调用其成员方法
[[[self.presentingViewControllerchildViewControllers]objectAtIndex:0]reloadarr];
[selfdismissModalViewControllerAnimated:YES];
【2】利用委托机制
二级类定义一个委托,一级类调用
22.h
@protocol showBookDelegate <NSObject>
-(NSString *)bookListRequest;
@end
@property (nonatomic,assign)id<showBookDelegate> delegate;
[delegatebookListRequest];
11.h
@interface 11 :UIViewController<showBookDelegate>
22.delegate =self;
7.数组内部排序
[_array sortUsingComparator:^NSComparisonResult(id obj1,id obj2) {
return [obj1compare:obj2]; }];
8.ScrollView
//设置参数
CGRect frame = [[UIScreen mainScreen]applicationFrame];
//初始化此参数下的ScrollView位置
scrollView = [[UIScrollView alloc]initWithFrame:frame];
//带位置及大小参数初始化
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[scrollView setFrame:CGRectMake(0.0f, 0.0f, 320.0, 480.0)];
//设置其大小参数
scrollView .contentSize = CGSizeMake(320.0f,scrollView .frame.size.height);
//设置scrollView的大小和image大小一致
scrollView.contentSize = image.size;
//允许按照屏幕大小进行翻页
scrollView .pagingEnabled = YES;
//允许滚动至边缘并出现view的背景
scrollView .bounces = YES;
//把对象添加到scrollView上
[scrollView addSubview:msv];
//把scrollView添加到view上
[self.view addSubview:scrollView ];
//允许上下拖动
scrollView.alwaysBounceVertical = YES;
//允许左右拖动
scrollView.alwaysBounceHorizontal = YES;
//放小至图片的一半
scrollView.minimumZoomScale = 0.5;
//放大至图片的二倍
scrollView.maximumZoomScale = 2.0;
//允许放大缩小
scrollView.bouncesZoom = YES;
//设置委托
scrollView .delegate = self;
9.委托概念
我上班的工作主要内容包括 [1]写代码 [2]写文档 [3]测试程序 [4]接电话 [5]会见客户
[1][2]我自己全权负责,但是后面[3][4][5]我不想或者不方便自己做,所以我想找个助手(delegate)帮我做这些事,于是我定了一个招聘要求(Protocol),里写明我的助手需要会做[3][4][5]这三件事。很快,我招到一个助手。
我.delegate = 助手;
于是以后每当我遇到需要测试程序或者接电话的活,我就把他转交给助手(delegate)去处理,助手处理完后如果有处理结果(返回值)助手会告诉我,也许我会拿来用。如果不需要或者没有结果,我就接着做下面的事。。
10.属性.参数格式的使用方法
声明:@property (修饰)类型属性名
@property(nonatomic,retain) id _delegate;
实现:@synthesize属性名
@synthesize -delegate;
修饰的类型:
readwrite: 变量可读写 ,生成get和set方法
readonly: 变量只可以读,需要手动添加setter,只有get方法(与assign无法同时选择)
assign:变量可以直接赋值,内存引用计数值不变,生成简单的封装,默认值为他,所有基本类型用他
retain: 对象进行一次引用,内存引用计数值+1
copy: 复制一个新的对象,内存引用计数值+1,复制一份使用(实质为引用计数加一,指向的是同一内存地址,而不是真正意义上的复制),一般字符串使用(官方例子中只有字符串有用)
nonatomic: 默认为atomic,在多线程是变量互斥,对象在不使用多线程时使用,提高性能
11.在NSdictionary中建议只用objectforkey就好了。
12.取文件内容
NSDictionary *data = [[NSDictionaryalloc]initWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"Points"ofType:@"plist"]];
13.在tabbar边缘添加数字
[self.tabBarItemsetBadgeValue:[NSStringstringWithFormat:@"%d",1]];
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(@"%@",self.tabBarItem.badgeValue);
self.tabBarItem.badgeValue=0;
[self.tabBarItemsetBadgeValue:[NSStringstringWithFormat:@"%d",0]];
}
14.内存管理
1.静态分析
静态分析就是使用Xcode自带的Analyze功能(Product-> Analyze),对代码进行静态分析,对于内存泄露(Potential Memory Leak),未使用局部变量(dead store),逻辑错误(Logic Flaws)以及API使用问题(API-usage)等明确的展示出来
Dead store 从未实用过的变量 删除即可
Memory Leak 的提示其实也比较好办,因为其提示已经足够详细,具体到了具体泄露的代码行。找到问题对症下药即可,忘记release的加上release,该放autorelease的地方加上auto release
2。动态分析
Instruments是Xcode自带的一个强大的应用分析工具,其功能并不局限于内存泄露的分析上,内存占用、CPU使用率等都是其分析的对象
连接实体机到开发机,选择选择运行设备为设备,点击Products-> Profile,经过编译后弹出一个Choose Trace Template or Existing Docunment双击leak进入下一级页面
自行摸索
先静态分析下,把能结局的内存泄漏隐患都给消除了,然后再动态分析
15.屏幕截图
UITapGestureRecognizer *tapGestureRecognizer2 = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(takeScreenshot:)];
tapGestureRecognizer2.numberOfTapsRequired =2;
UITapGestureRecognizer *tapGestureRecognizer3 = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(takeScreenshot:)];
tapGestureRecognizer3.numberOfTapsRequired =3;
[tapGestureRecognizer2 requireGestureRecognizerToFail:tapGestureRecognizer3];
[self.viewaddGestureRecognizer:tapGestureRecognizer2];
[self.viewaddGestureRecognizer:tapGestureRecognizer3];
- (void) takeScreenshot:(UITapGestureRecognizer *)gestureRecognizer
{
CGFloat scale = gestureRecognizer.numberOfTapsRequired -1.0f;
UIGraphicsBeginImageContextWithOptions(self.inputAccessoryView.frame.size,NO, scale);
CGContextRef context =UIGraphicsGetCurrentContext();
[self.inputAccessoryView.layerrenderInContext:context];
UIImage *screenshot =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)lastObject];
[[NSFileManagerdefaultManager]createDirectoryAtPath:documentsDirectorywithIntermediateDirectories:YESattributes:nilerror:NULL];
NSString *scaleString = scale !=1.f ? [NSStringstringWithFormat:@"@%gx", scale] :@"";
NSString *screenshotName = [NSStringstringWithFormat:@"%@%@.png", [[selfinputAccessoryView]class], scaleString];
NSString *screenshotPath = [documentsDirectorystringByAppendingPathComponent:screenshotName];
[UIImagePNGRepresentation(screenshot)writeToFile:screenshotPathatomically:YES];
system([[NSStringstringWithFormat:@"open \"%@\"", screenshotPath]fileSystemRepresentation]);
}
16.过渡动画
[UIViewbeginAnimations:@"up"context:nil];
[UIViewsetAnimationDuration:1.0];
[self.viewsetFrame:CGRectMake(0, -190,320,460)];
[UIViewcommitAnimations];