pieces colloction

  • formatter设置: [formatter stringFromDate:date]

1
2
3
4
5
NSDate *date = _datePicker.date;
NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *tempStr = [formatter stringFromDate:date];
//2014-05-06 16:22:22 -> yyyy-MM-dd HH:mm:ss
  • appearance 全局布局以及attributes设置navigationBar

1
2
3
4
5
6
7
//BarTintcolor
[[UINavigationBar appearance]setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance]setTranslucent:NO];
[UIView appearance].backgroundColor = [UIColor whiteColor];
[[UINavigationBar appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorFromHexCode:@"534530"],NSFontAttributeName:[UIFont systemFontOfSize:22]}];
[[UITableView appearance]setSeparatorColor:[UIColor colorFromHexCode:@"9c896f"]];
[[UIBarButtonItem appearance]setTintColor:[UIColor colorFromHexCode:@"726754"]];
1
2
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil];
[nav.navigationBar setTitleTextAttributes:attributes];
  • 时间戳

    当前时间距离1970年的秒数

1
2
NSDate *date = [NSDate date];//当前时间
NSTimeInterval timeStamp = [date timeIntervalSince1970];
  • 本地文件url

    1
    [NSURL fileURLWithPath:path]
  • 深拷贝浅拷贝

    只有multabalAry = [multabalAry copy]才是浅拷贝?

  • 自定义分组tableView的headView

注册

1
[_tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"HeaderView"];

重用

1
2
3
4
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UITableViewHeaderFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HeaderView"];
return view;
}

  • 关闭系统对图片的渲染让图片始终保持原样,storyboard图片属性 Render as:original image

  • 取随机数 arc4random()

  • 线程单例

1
2
3
4
5
6
7
8
9
10
+(TwoViewController *)sharedTwoVC{
static TwoViewController *twoVc = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
twoVc = [self new];
twoVc.navi = [[UINavigationController alloc]initWithRootViewController:twoVc];
twoVc.title = @"two";
});
return twoVc;
}
  • tableview去掉横线左右空白

1
2
3
cell.separatorInset = UIEdgeInsetsZero;
cell.layoutMargins = UIEdgeInsetsZero;
cell.preservesSuperviewLayoutMargins = NO;
  • xib创建view时,自定义view的layer

1
2
3
4
-(void)awakeFromNib{
[self.gifImage.layer setCornerRadius:9];
[self.gifImage.layer setMasksToBounds:YES];
}
  • 启动页设置

  • 生命周期

1-8,4-7,5-6

  1. init (初始化)
  2. loadView (执行一次)

    手动重写时,需要手动创建Controller的view(可以手动自定义一个view或者[super loadView])(如果不重写loadView会自动通过[super loadView])

  3. viewDidLoad (执行一次)
  4. ViewWillAppear (多次执行)
  5. ViewDidAppear (多次执行)

    视图跳转时

  6. ViewWillDisAppear (多次执行)
  7. ViewDidDisAppear (多次执行)
  8. dealloc (销毁控制器)

###

  • 回传数据方式 return和block回调的区别:return方式是顺序执行完才返回,会占据当前线程资源,不允许其他任务执行,而block不会,block则是在耗时操作做完后“通知”你,然后回调

    (比方 :去买手抓饼,block形式:你把电话号给了老板,让他做完通知你,你可以去做其他事(回调))

    return:你在旁边等着,直到饼做完,才能做其他事
    

    -(KindModel *)func{
    //各种操作,耗时
    return XX;
    }