美文网首页
小点总结

小点总结

作者: wq04200 | 来源:发表于2016-11-01 23:48 被阅读16次

日期问题 :

获取当前月天数
NSCalendar *calendar = [NSCalendar currentCalendar];

NSRange range = [calendar rangeOfUnit:NSCalendarUnitDay  inUnit:NSCalendarUnitMonth forDate:[NSDate date]];

NSUInteger numberOfDaysInMonth = range.length;
获取当前、年、月、日
NSCalendar*calendar = [NSCalendarcurrentCalendar];

unsignedunitFlags =NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay;

NSDateComponents*components = [calendarcomponents:unitFlagsfromDate:[NSDatedate]];

NSIntegeriCurYear = [componentsyear];//当前的年份

NSIntegeriCurMonth = [componentsmonth];//当前的月份

NSIntegeriCurDay = [componentsday];//当前的号数

NSInteger i = [self howManyDaysInThisMonth:2];

NSLog(@"%ld",(long)i);

// 获取今年指定月的天数

- (NSInteger)howManyDaysInThisMonth :(NSInteger)imonth {
int year = [[self years][0] intValue];

if((imonth == 1)||(imonth == 3)||(imonth == 5)||(imonth == 7)||(imonth == 8)||(imonth == 10)||(imonth == 12))

return 31 ;

if((imonth == 4)||(imonth == 6)||(imonth == 9)||(imonth == 11))

return 30;

if((year%4 == 1)||(year%4 == 2)||(year%4 == 3))
{
return 28;
}
if(year%400 == 0)
return 29;

if(year%100 == 0)
return 28;
return 29;
}
#pragma mark 获取当前的年月

- (NSArray *) years {

NSMutableArray *yearArr = [[NSMutableArray alloc]init];

NSDate *now = [NSDate date];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSUInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth;

NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];

NSInteger year = [dateComponent year];

NSInteger month = [dateComponent month];

[yearArr addObject:@(year)];

[yearArr addObject:@(month)];

return yearArr;

}

tableView表头:

通过xib写了一个view成为tableview的tableHeaderView的时候,xib 的布局整个都乱了,用纯代码写了一个测试的,什么问题都没有 在viewdidload中加载xib,设置,出现bug,是因为viewdidload方法中获取到的设置tableHeaderView的尺寸是不对的,应该到viewDidLayoutSubView中设置 ,前提是你一定要先设置 然后在去写 self.tableview.tableHeaderView = A(这句话在viewdidload写就好),这样就可以解决了

- (void)viewDidLayoutSubviews{
//表头
MycoinHeaderView *headerView = [[[NSBundle mainBundle]loadNibNamed:@"MycoinHeaderView" owner:self options:nil]lastObject];

headerView.frame = CGRectMake(0, 0, ScreenWidth, 166);

self.tableView.tableHeaderView = headerView;
}

JSONModel基本使用

服务器数据如图


屏幕快照 2016-11-07 下午1.44.41.png

model中写法如下

.h文件
#import "JSONModel.h"
@protocol ChartModel//涉及数组需要写的
@end

@interface ChartModel : JSONModel//最里层的属性model

@property (nonatomic,strong) NSString *id;
@property (nonatomic,strong) NSString *createtime;
@property (nonatomic,strong) NSString *isdelete;
@property (nonatomic,strong) NSString *rate;
@end

@interface dataModel : JSONModel
@property (nonatomic,strong) NSArray<ChartModel>*IncomerightRateList;//数组model
@end


.m文件:
#import "ChartModel.h"

@implementation ChartModel
@end

@implementation dataModel
@end

API.m中请求到数据后写法如下

NSMutableArray *charArr = [NSMutableArray array];
            charArr = [ChartModel arrayOfModelsFromDictionaries:responseObject[@"data"][@"IncomerightRateList"]  error:nil];

有时候为了对特殊json数据处理或者特殊的属性处理 如和系统属性id冲突等 会先创建一个model基类 (baseModel——>继承JSONModel) 然后让新建的model继承与baseModel

1.首先声明一个继承自JSONModel的基类:
//.h

#import "JSONModel.h"

@interface BaseModel : JSONModel
@end

//.m

@implementation BaseModel

/**用于将服务器传过来的以下划线字段转化为模型的驼峰类型:比如上面的available_predeposit, 但模型中我们的字段如果我们写为(通常我们都这么写)availablePredeposit,如果不重写该函数则availablePredeposit就无法赋值*/
+ (JSONKeyMapper *)keyMapper {
    return [JSONKeyMapper mapperFromUnderscoreCaseToCamelCase];
}

/**声明模型中的字段可以存在或不存在服务器的字段,
 否则模型不会被赋值,比如说下面的Model中如果有字段code1,如果没这样重写这个方法,这整个model就不会被赋值,解析的结果是nil。
 */
+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    return YES;
}
@end

http://www.itstrike.cn/Question/06350247-ded1-4bc5-aa8a-bf5bb1ea2efe.html
http://blog.csdn.net/qiyexiluo/article/details/51746543
更多用法参考http://www.jianshu.com/p/3c49e5eb1602

设置滑动的时候隐藏 navigationbar

第1种: 
navigationController.hidesBarsOnSwipe = Yes 
第2种: 
//1.当我们的手离开屏幕时候隐藏 
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:
(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { 
   if(velocity.y > 0) { 
             [self.navigationController setNavigationBarHidden:YES animated:YES]; 
     } 
   else { 
               [self.navigationController setNavigationBarHidden:NO animated:YES]; 
         } 
  } 
velocity.y这个量,在上滑和下滑时,变化极小(小数),但是因为方向不同,有正负之分,这就很好处理 了。

设置某一行cell的分割线消失

chartCell.separatorInset = UIEdgeInsetsMake(0, 0, 0, chartCell.bounds.size.width);

数组排序

数组排序的 key : 例子如下

CHSAssetGroup *group_a = [[CHSAssetGroup alloc] init];
group_a.name = @"a";
group_a.creationDate = @"2016-5-28";
CHSAssetGroup *group_b = [[CHSAssetGroup alloc] init];
group_b.name = @"b";
group_b.creationDate = @"2016-8-23";
CHSAssetGroup *group_c = [[CHSAssetGroup alloc] init];
group_c.name = @"c";
group_c.creationDate = @"2016-6-21";
NSArray *array = @[group_a, group_b, group_c];

排序如下

// Key: 按照排序的key; ascending: YES为升序, NO为降序。
 NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"creationDate" ascending:NO]; 
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sorter count:1]; 
NSArray *sortedArray = [array sortedArrayUsingDescriptors:sortDescriptors]; 
NSLog(@"%@", sortedArray);

NSSortDescriptor 指定用于对象数组排序的对象的属性。sortedArray 即为排序后的数组,其元素顺序为 @[group_b, group_c, group_a];

如果是要求对象按照多可 key 排序,比如先按 name 排序,再按 creationDate 排序。那就创建两个descriptor,将两个 descriptor 放到数组里一起传给需要排序的数组。

NSSortDescriptor *nameSorter = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:NO]; 
NSSortDescriptor *dateSorter = [[NSSortDescriptor alloc] initWithKey:@"creationDate" ascending:NO]; 
NSArray *sortDescriptors2 = [[NSArray alloc] initWithObjects:nameSorter, dateSorter, nil];

可变数组排序

如果想要排序的数组是一个可变数组,则只需要调用 sortUsingDescriptors:
方法对自身进行排序即可:

NSMutableArray *mutableArray = [NSMutableArray arrayWithObjects:group_a, group_b, group_c, nil];
 NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"creationDate" ascending:NO]; 
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sorter count:1]; 
[mutableArray sortUsingDescriptors:sortDescriptors] NSLog(@"%@", mutableArray);

字符串数组排序

如果对象就是NSString,就是字符串数组排序,将 sortdescriptor
key 直接指定为 nil,就直接排序对象,而不是对象的某一个属性了。

NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];
NSArray *descriptors = [NSArray arrayWithObject:descriptor]; 
NSArray *myDataArray = [NSArray arrayWithObjects:@"what", @"xman", @"highligth", @"mountain", @"success", @"Apple", nil]; 
NSArray *sortedArray = [myDataArray sortedArrayUsingDescriptors:descriptors]; 
NSLog(@"%@", sortedArray);

给tableView设置背景不动的图片:

1、//设置表的背景视图

   tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"w_yin"]];

2、使之滑动时可以看到效果需设置Section的区头或者区角
//并使区头视图背景色为透明色即可

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *vvv  = [UIView new];
    vvv.backgroundColor=[UIColor clearColor];
    return vvv;
}

3、如果想让cell上也能看到效果可以给cell局部设置透明,在需要不透明的地方假不透明控件即可

字符串中有特殊符号%:

NSInteger count = 50;//%是一个特殊符号 如果在NSString中用到%需要如下写法
NSString *string = [NSString stringWithFormat:@"%zd%%",count];
//输出结果是: 50%NSLog(@"%@", string);

用0补全的方法:

NSInteger count = 5;//02代表:如果count不足2位 用0在最前面补全(2代表总输出的个数)
NSString *string = [NSString stringWithFormat:@"zd",count];
//输出结果是: 05NSLog(@"%@", string);

相关文章

  • 小点总结

    日期问题 : tableView表头: 通过xib写了一个view成为tableview的tableHeaderV...

  • 容易忽略的那些小点总结

    容易忽略的那些小点总结 (一) —— UIView UIViewTintAdjustmentMode相关(一)容易...

  • “升华怪”,你身边有没?

    何为“升华怪”?先科普知识,“升华怪”是喜欢总结别人说出的话,能从小点,小事上,总结概括出宇宙的真理。 总是觉得,...

  • 新媒体实战工作几点反思

    回顾从业的几年,自己不太爱总结,趁着这次日更的机会,将工作中的一些经验做一些总结。以下分成几个小点来进行总结: 1...

  • 2.8总结

    总结: 今天给网页加的动画有点问题,动的时候有点抖 网页还有一小点 算法又没做

  • Kotlin中的const常量

    本来想作为kotlin一周总结的一个小点总结的,结果越来越多了,就单独拉出来练练 变量和常量 一般kotlin用到...

  • 小点

    今天是大姨妈来的第二天。我觉得我的状态并不好。因为早上起来嗓子就开始疼。而且鼻子也开始出现了问题。就是一个感冒的状...

  • 小点

    小点,是我刚认识不久的姑娘。 今天,看到她发的微诗时,突然就想写一写她。 2018年末时,有一天发现一个陌生的头像...

  • 练字day53

    [TOC] 内容 时间:2016/12/20 耗时20分钟 截图 总结 残字左边适当写小点,整体就好看一些

  • 前端学习go语言避坑指南

    本人是前端,最近在学习go,总结一些学习的小点。前端都是通过export default 和import来完成模块...

网友评论

      本文标题:小点总结

      本文链接:https://www.haomeiwen.com/subject/cskyuttx.html