一個普通 iOS 碼農的幾個小項目相關知識點總結

題記:在開發的路途上,有的人走的很深很遠,而對於停留在初級階段的我來講,還要學的、經歷的還有不少...

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;}];
  • 經典代碼,標籤 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;
           }
      }
 }
  • 解析 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;
  • 使用 AFN 配置服務器本身建立的 https 證書的 https
    + 使用 AFN 忽略全部 https 證書、不檢測域名的策略sql

    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;

}
  • PNChart 修改 x 軸 label 的位置,源碼方法
- (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,

}
  • PNChart 修改曲線 水平方向日後總體便移一點距離,源碼方法
- (void)calculateChartPath:(NSMutableArray *)chartPath andPointsPath:(NSMutableArray *)pointsPath andPathKeyPoints:(NSMutableArray *)pathPoints andPathStartEndPoints:(NSMutableArray *)pointsOfPath {


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


}
相關文章
相關標籤/搜索