1.// 判断是否第一次进入
if (![[NSUserDefaults standardUserDefaults]boolForKey:@"everLaunched"]) {
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"everLaunched"];
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"firstLaunch"];
}
else{
[[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"firstLaunch"];
}
if ([[NSUserDefaults standardUserDefaults]boolForKey:@"firstLaunch"]) {
NSLog(@"这是第一次进入");
}
else{
NSLog(@"这不是第一次进入");
}
2.导航添加左按钮
_leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 30)];
[_leftBtn setTitle:@"left" forState:UIControlStateNormal];
[_leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * leftItem = [[UIBarButtonItem alloc]initWithCustomView:_leftBtn];
self.navigationItem.leftBarButtonItem = leftItem;
3.<#name#>
创建代码块
拖动一块代码到右边 最下角{}里,可以修改代码块的 快捷方式(你能快速打出的字母),对于变量可以用<#name#>来提示,用delete来确认删除
4.tableView上添加控件
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 2, 100, 40)];
label.text = [NSString stringWithFormat:@"第%d行",indexPath.row];
label.textColor = [UIColor redColor];
[cell.contentView addSubview:label];
5.// 汉字转码,可以把json中的汉字直接显示,什么时间研究一下
NSString *oriString = @"\u67aa\u738b";
NSString * escapedString = [oriString stringByRemovingPercentEncoding];
NSLog(@"%@",escapedString);
6.将电话号码转为规则输出
// 原始号码
NSString * originalString = @"(123) 123123 abc";
NSMutableString * strippedString = [NSMutableString stringWithCapacity:originalString.length];
NSScanner * scanner = [NSScanner scannerWithString:originalString];
NSCharacterSet * numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
while ([scanner isAtEnd] == NO) {
NSString * buffer;
if ([scanner scanCharactersFromSet:numbers intoString:&buffer]) {
[strippedString appendString:buffer];
}
// --------- Add the following to get out of endless loop
else {
[scanner setScanLocation:([scanner scanLocation] + 1)];
}
// --------- End of addition
}
NSLog(@"%@", strippedString); // "123123123"
7.NSDate
NSDate * date1 = [NSDate date];
NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
// 使时间戳格式化输出
// formatter.dateFormat = @"yyyy年MM月dd日 HH时mm分ss.S秒";
formatter.dateFormat = @"yyyy年MM月dd日 HH时mm分s秒";
formatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"HKT"]; //用香港时间输出,不用在往后数8个小时
NSString * str = [formatter stringFromDate:date1];
NSLog(@"%@",str);
label.text = str; //利用label的text来接受时间,可以当计时器用
8.笨方法测试控件
-(void)creatBtn{
NSArray * buttonNames = @[@"UISegmentedControl",@"UIActivityIndicatorView",@"UIStepper",@"UIProgressView",@"UISwitch",@"UISlider",@"UIAlertView"]; //新加类十分方便
for (int i = 0; i < buttonNames.count; i ++) {
UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(10, 20 + i * 40, [UIScreen mainScreen].bounds.size.width - 20, 35);
[btn setTitle:[buttonNames objectAtIndex:i] forState:UIControlStateNormal];
btn.backgroundColor = [UIColor orangeColor];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(nextViewController:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
}
-(void)nextViewController:(id)sender{
UIButton * btn = (UIButton *)sender;
// 获取类名称
NSString * className = [NSString stringWithFormat:@"%@ViewController",btn.currentTitle];
// 通过类找到对应的类
Class class = NSClassFromString(className);
// 通过类实例化对象
UIViewController * viewController = [[class alloc]init];
// 进入创建界面
[self presentViewController:viewController animated:YES completion:nil];
}
9.. // “%.02f小数点
10.打印沙盒路径
NSArray * arr = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString * path = [arr objectAtIndex:0];
NSLog(@”%@”,path);
输出:/Users/****/Library/Developer/CoreSimulator/Devices/81FEB617-****-46CC-9D1C-76B86B594963/data/Containers/Data/Application/C1AAB589-****-4ADA-8B4F-6CF3D1B6E703/Library/Documentation
NSString * sandPath = [NSString stringWithFormat:@"%@/Documents",NSHomeDirectory()];
// 在上面打断点,在调试行 写 po sandPath可以在调试界面输出
NSLog(@"%@",sandPath);
输出:/Users/****/Library/Developer/CoreSimulator/Devices/81FEB617-B8D0-46CC-9D1C-**********/data/Containers/Data/Application/C1AAB589-92F6-4ADA-8B4F-6CF3D1B6E703/Documents