开发中遇到的一些坑

失败是成功之母,开发中踩坑的过程就是你慢慢变牛逼的过程,坑无高低贵贱之分,随手记下

条件断点中字符串判断不起作用

开发中遇到的一些坑_第1张图片
条件断点

需要转一下:

[cityName isEqualToString: [NSString stringWithUTF8String:"高雄"]];

endEditing 屏幕闪烁

收起键盘能用resignFirstResponder就不要用endEditing,push控制器会有个bug

Masonry控制约束优先级的一些坑

灵活设置多个约束优先级是一个比较优雅的布局方案

    [self.currentPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(MBoxMarginHorizontal));
        make.top.equalTo(self.nameLabel.mas_bottom).offset(MBoxMarginVertical).priorityLow();
        self.showTagsConstraint = make.top.equalTo(self.discountLabel.mas_bottom).offset(MBoxMarginVertical).priorityHigh();
    }];
    [self.showTagsConstraint deactivate];

  • Masonry控制约束是否生效应该都设置优先级,不然会约束报警
  • 约束属性用strong修饰
  • 控件默认内容约束优先级是750,高于normal,例如Label
  • deactivate在block外调用

控件设置内容抗压缩优先级

[label setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

参考资料

1.如何使用Masonry设计复合型cell

打包前build报错

开发中遇到的一些坑_第2张图片
条件断点

开发中遇到的一些坑_第3张图片
条件断点

解决方法:shift+option+command+K

NSTimer+Block Crash

这个API iOS10才有

[NSTimer timerWithTimeInterval:0.5 repeats:YES block:^(NSTimer * _Nonnull timer) {
        
}];

NSURLCache的坑

  • 请求文件时,NSURLRequestCachePolicy 策略下如果要不缓存文件,需要在网络返回的header的Cache-Control中添加no-store字段。

  • 最好不要去手动设置NSURLCache的缓存大小(也许在application:didFinishLaunchingWithOptions里设置不会有问题,待验证)

 NSURLCache *URLCache = [[NSURLCache alloc] 
    initWithMemoryCapacity:4 * 1024 * 1024 
    diskCapacity:20 * 1024 * 1024
    diskPath:nil];
 [NSURLCache setSharedURLCache:URLCache];

可能会导致在NSURLRequestCachePolicy策略下第一次缓存有效,过期后缓存不再生效,每次都会发出请求的问题。

Autolayout布局的可变tableHeaderView

  • 在设置数据后需要更新headerView

    self.headerView.model = model;

    CGFloat height = [self.headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    CGRect frame = self.headerView.frame;
    frame.size.height = height;
    self.headerView.frame = frame;
    
    self.tableView.tableHeaderView = self.headerView; //只有重新设置tableHeaderView 才会刷新高度


stringByDeletingLastPathComponent

  NSString *host = @"https://qa1.cn.memebox.com/mobilev42";
  NSString *deleteLastPathComponent = [host stringByDeletingLastPathComponent];
//deleteLastPathComponent -> https:/qa1.cn.memebox.com 
//https后面少了一个/

更新pod版本以后Jenkins打包会出现类似下面这样的问题。

CompileC /Users/memebox/Library/Developer/Xcode/DerivedData/MWProjectTemplate-byqaabrinqkdvkbqlwomhnwqxsel/Build/Intermediates/Pods.build/Release-iphoneos/AFNetworking.build/Objects-normal/armv7/AFNetworkReachabilityManager.o AFNetworking/AFNetworking/AFNetworkReachabilityManager.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler

解决方法:打包机器终端执行下pod setup

你可能感兴趣的:(开发中遇到的一些坑)