题记:在开发的路途上,有的人走的很深很远,而对于停留在初级阶段的我来说,还要学的、经历的还有很多...
list
  • sqlite 数据库中,当把表里的数据都清空时,下次插入的数据的 id 主键不会从 0 开始。保险起见 下次从数据库获取数据时先获取第一个的 id 主键,不知道还有没有其他简单的方法
  • 如果设置了 tableView 的上边距再使用 MJRefresh时,刷新控件会错位,可使用忽略 tableView等的内边距方法,该方法在类:MJRefreshHeader 里,方法名 ignoredScrollViewContentInsetTop
  • 填写表单型的 tableView,用到了 textField 要注意需要显示的是 textField.text 还是 textField.placeholder,注意 cell 循环引用。 需要写多种类似的表格时,UI 界面就一套,用本地不同的 plist 数据去控制表格,给数据很多属性来区分:增加正则判断数值,增加样式...
  • kvc 修改已有类的私有属性是可以的,使用苹果未暴露的类的私有属性和方法是不允许的
  • 一个页面多次异步请求数据(使用 AFN),但需要在最后一次请求数据的时候才刷新 UI
    + 异步请求嵌套,在一次异步请求成功或失败的回调里进行下一次请求,适合于两次请求有明显的先后关系时
    + 用一个变量做标记,在每一次请求成功的回调里 需要写以下两个方面的代码:①将变量加个1,②如果变量等于请求的个数就执行请求完成、刷新UI的方法 ,当然请求失败也需要这样处理
    + 其他方法...?
  • 谓词 NSPredicate 的使用
    + objc NSArray *tmpArray = [self.zhiBiaoArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"month == '%@'", month]]]; + objc NSString *regex = @"^[0-9]*$"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self matches %@",regex]; return [predicate evaluateWithObject:text];
  • 根据数据中的对象的属性排序
tmpArray = [tmpArray sortedArrayUsingComparator:^NSComparisonResult(SuiFangItem *obj1, SuiFangItem *obj2) {
    return [obj1.SUBDATE compare:obj2.SUBDATE] == NSOrderedAscending;}];
    tmpArray = [tmpArray sortedArrayUsingComparator:^NSComparisonResult(SuiFangItem *obj1, SuiFangItem *obj2) {
    return [obj1.SUBDATE compare:obj2.SUBDATE] == NSOrderedAscending;}];
  • 经典代码,标签 for 循环排序设置标签的 xy
for (NSInteger i = 0; i < tagBtnArray.count; i ++) {
       UIButton *tagBtn = tagBtnArray[i];
       if (i == 0) {
         tagBtn.fd_x = 0;
         tagBtn.fd_y = 0;
         } else {
           UIButton *previousBtn = tagBtnArray[i -1];
           tagBtn.fd_x = CGRectGetMaxX(previousBtn.frame) + 10;
           tagBtn.fd_y = previousBtn.fd_y;
           if ((tagViewW - tagBtn.fd_x) < tagBtn.fd_width) {tagBtn.fd_x = 0;
    tagBtn.fd_y = CGRectGetMaxY(previousBtn.frame) + 10;
           }
      }
 }
 for (NSInteger i = 0; i < tagBtnArray.count; i ++) {
       UIButton *tagBtn = tagBtnArray[i];
       if (i == 0) {
         tagBtn.fd_x = 0;
         tagBtn.fd_y = 0;
         } else {
           UIButton *previousBtn = tagBtnArray[i -1];
           tagBtn.fd_x = CGRectGetMaxX(previousBtn.frame) + 10;
           tagBtn.fd_y = previousBtn.fd_y;
           if ((tagViewW - tagBtn.fd_x) < tagBtn.fd_width) {tagBtn.fd_x = 0;
    tagBtn.fd_y = CGRectGetMaxY(previousBtn.frame) + 10;
           }
      }
 }
  • 解析 xml 值格式 的数据,xml 属性格式 的可使用系统的
    + 使用 XMLDictionary 将 xml 转成字典,再解析
  • 服务器返回一堆带有月份的数据,服务器并未做按月分组,本地实现按月分组
// 获得数据中存在的月份,共有哪几个月份
    NSMutableArray *monthArray = [NSMutableArray array];
    ZhiBiaoItem *firstItem = self.zhiBiaoArray[0];
    [monthArray addObject:firstItem.month];

    for (NSInteger i = 1; i < self.zhiBiaoArray.count; i ++) {
        ZhiBiaoItem *item = self.zhiBiaoArray[i];
        if (![item.month isEqualToString:firstItem.month]) {
            if ([monthArray containsObject:item.month]) {
                continue;
            }
            [monthArray addObject:item.month];
        }
    }

    self.monthArray = monthArray;

    // 根据月份进行分组
    NSMutableDictionary *resultDict = [NSMutableDictionary dictionary];
    for (NSString *month in monthArray) {
        NSArray *tmpArray = [self.zhiBiaoArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"month == '%@'", month]]];
        [resultDict setObject:tmpArray forKey:month];
    }

    self.resultDict = resultDict;
    // 获得数据中存在的月份,共有哪几个月份
    NSMutableArray *monthArray = [NSMutableArray array];
    ZhiBiaoItem *firstItem = self.zhiBiaoArray[0];
    [monthArray addObject:firstItem.month];

    for (NSInteger i = 1; i < self.zhiBiaoArray.count; i ++) {
        ZhiBiaoItem *item = self.zhiBiaoArray[i];
        if (![item.month isEqualToString:firstItem.month]) {
            if ([monthArray containsObject:item.month]) {
                continue;
            }
            [monthArray addObject:item.month];
        }
    }

    self.monthArray = monthArray;

    // 根据月份进行分组
    NSMutableDictionary *resultDict = [NSMutableDictionary dictionary];
    for (NSString *month in monthArray) {
        NSArray *tmpArray = [self.zhiBiaoArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"month == '%@'", month]]];
        [resultDict setObject:tmpArray forKey:month];
    }

    self.resultDict = resultDict;
  • 使用 AFN 配置服务器自己创建的 https 证书的 https
    + 使用 AFN 忽略所有 https 证书、不检测域名的策略
AFSecurityPolicy *secPolicy        = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
      secPolicy.allowInvalidCertificates = YES;
      secPolicy.validatesDomainName      = NO;
      _mgr.securityPolicy                = secPolicy;
      AFSecurityPolicy *secPolicy        = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
      secPolicy.allowInvalidCertificates = YES;
      secPolicy.validatesDomainName      = NO;
      _mgr.securityPolicy                = secPolicy;
+ `配置 AFN 本地 https证书? 不清楚如何配置`
+
  • PNChart 修改 节点label 的大小,在源码中修改
- (CATextLayer *)createPointLabelFor:(CGFloat)grade pointCenter:(CGPoint)pointCenter width:(CGFloat)width withChartData:(PNLineChartData *)chartData {
    CATextLayer *textLayer = [[CATextLayer alloc] init];
    [textLayer setAlignmentMode:kCAAlignmentCenter];
    [textLayer setForegroundColor:[chartData.pointLabelColor CGColor]];
    [textLayer setBackgroundColor:[[[UIColor whiteColor] colorWithAlphaComponent:0.8] CGColor]];
    [textLayer setCornerRadius:textLayer.fontSize / 8.0];

    if (chartData.pointLabelFont != nil) {
        [textLayer setFont:(__bridge CFTypeRef) (chartData.pointLabelFont)];
        textLayer.fontSize = [chartData.pointLabelFont pointSize];
    }

    CGFloat textHeight = textLayer.fontSize * 1.1;
    CGFloat textWidth = width * 7;
    CGFloat textStartPosY;

}
- (CATextLayer *)createPointLabelFor:(CGFloat)grade pointCenter:(CGPoint)pointCenter width:(CGFloat)width withChartData:(PNLineChartData *)chartData {
    CATextLayer *textLayer = [[CATextLayer alloc] init];
    [textLayer setAlignmentMode:kCAAlignmentCenter];
    [textLayer setForegroundColor:[chartData.pointLabelColor CGColor]];
    [textLayer setBackgroundColor:[[[UIColor whiteColor] colorWithAlphaComponent:0.8] CGColor]];
    [textLayer setCornerRadius:textLayer.fontSize / 8.0];

    if (chartData.pointLabelFont != nil) {
        [textLayer setFont:(__bridge CFTypeRef) (chartData.pointLabelFont)];
        textLayer.fontSize = [chartData.pointLabelFont pointSize];
    }

    CGFloat textHeight = textLayer.fontSize * 1.1;
    CGFloat textWidth = width * 7;
    CGFloat textStartPosY;

}
  • PNChart 修改 x 轴 label 的位置,源码方法
- (void)setXLabels:(NSArray *)xLabels withWidth:(CGFloat)width  {
}
- (void)setXLabels:(NSArray *)xLabels withWidth:(CGFloat)width  {
}
  • PNChart 修改 y 轴,源码方法
- (void)setYLabels {
PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (NSInteger) _chartCavanHeight - 10, (NSInteger) _chartMarginBottom, (NSInteger) _yLabelHeight)];

CGRect labelFrame = CGRectMake(0.0,
                    (NSInteger) (_chartCavanHeight + _chartMarginTop - index * yStepHeight) -10,

}
- (void)setYLabels {
PNChartLabel *minLabel = [[PNChartLabel alloc] initWithFrame:CGRectMake(0.0, (NSInteger) _chartCavanHeight - 10, (NSInteger) _chartMarginBottom, (NSInteger) _yLabelHeight)];

CGRect labelFrame = CGRectMake(0.0,
                    (NSInteger) (_chartCavanHeight + _chartMarginTop - index * yStepHeight) -10,

}
  • PNChart 修改曲线 水平方向往后整体便移一点距离,源码方法
- (void)calculateChartPath:(NSMutableArray *)chartPath andPointsPath:(NSMutableArray *)pointsPath andPathKeyPoints:(NSMutableArray *)pathPoints andPathStartEndPoints:(NSMutableArray *)pointsOfPath {


int x = i * _xLabelWidth + _chartMarginLeft + _xLabelWidth / 2.0 + 6;


}
- (void)calculateChartPath:(NSMutableArray *)chartPath andPointsPath:(NSMutableArray *)pointsPath andPathKeyPoints:(NSMutableArray *)pathPoints andPathStartEndPoints:(NSMutableArray *)pointsOfPath {


int x = i * _xLabelWidth + _chartMarginLeft + _xLabelWidth / 2.0 + 6;


}