蓝懿iOS 技术内容和心得 12.13

来源:互联网 发布:淘宝密码怎么找回来 编辑:程序博客网 时间:2024/05/16 08:59
  • 获取当前时间的秒数:拿到1970年到现在过的总秒数;

NSTimeInterval time = [[NSDate date] timeIntervalSince1970];

long long int date = (long long int)time;

NSLog(@”date\n%lld”, date); //1295322949

//把秒数转化成yyyy-MM-dd hh:mm:ss格式

NSDate *dd = [NSDate dateWithTimeIntervalSince1970:date];

NSLog(@”d:%@”,dd); //2011-01-18 03:55:49 +0000

//微博返回的时间格式​,字母为固定的,大小写不能错;

    NSDateFormatter *fmt = [[NSDateFormatteralloc] init];

//    EEE星期 MMM月 dd日 HH小时 mm分 ss秒 Z时区 yyyy年

    fmt.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";

    //英文

  fmt.locale = [[NSLocalealloc] initWithLocaleIdentifier:@"en_US"];

       

//

 获得微博发布的具体时间 (倒推回去)

    NSDate *createDate = [fmt dateFromString:_created_at];

    //获取当前时间对象

    NSDate *nowDate = [NSDate date];

    long createTime = [createDate timeIntervalSince1970];

    long nowTime = [nowDate timeIntervalSince1970];

    long time = nowTime-createTime;

    if (time<<span se-mark="1">60) {

        return @"刚刚";

    }else if (time<<span se-mark="1">3600){

        return [NSString stringWithFormat:@"%ld分钟前",time/60];

    }else if (time<<span se-mark="1">3600*24){

        return [NSString stringWithFormat:@"%ld小时前",time/3600];

    }

//自己重新定义显示格式​

        fmt.

dateFormat

 = @"MM月dd日 HH:mm";

    return [fmt stringFromDate:createDate];

另外在分享一些常见 的错误:

1.[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key resultLabel.出错原因:sb控件和代码关联出错解决方案:找到相对应的页面的黄色圆点(ViewController)在此上面右键 删除 黄色叹号2.<__NSArrayM: 0x7c0320b0> was mutated while being enumerated.出错原因:forin循环时修改了数组 但继续循环了解决方案: 修改数组后 加break或return3.-[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 0]'出错原因:数组角标越界解决方案:角标的取值 要小于数组的count4.-[ViewController addZombX]: unrecognized selector sent to instance 0x79174e00'出错原因:在ViewController中找不到方法

解决方案:在某个类中没有实现这个方法  或者是对象类型错了

5.This application is modifying the autolayout engine from a background thread出错原因:子线程中修改了界面解决方案:回到主线程修改就可以了6.An

instance 0x7fb6dad221e0 of class Mouse was deallocated

while key value observers were still registered with it

原因:监听了一个已经被释放的对象

解决方案:在适当的位置删除监听

    学习ios  重要还是要理清楚思路  在做或者看老师代码的时候 自己多想想为什么  不要自己看着就抄       另外还是要推荐一下 蓝懿IOS这个培训机构  和刘国斌老师刘国斌老师还是很有名气的,听朋友说刘老师成立了蓝懿iOS,,老师讲课方式很独特,能够尽量让每个人都能弄明白,有的比较难懂的地方,如果有的地方还是不懂得话,老师会换个其它方法再讲解,这对于我们这些学习iOS的同学是非常好的,多种方式的讲解会理解得更全面,这个必须得给个赞,嘻嘻,还有就是这里的学习环境很好,很安静,可以很安心的学习,安静的环境是学习的基础,小班讲课,每个班20几个学生,学习氛围非常好,每天都学到9点多才离开教室,练习的时间很充裕,而且如果在练习的过程中有什么困难,随时可以向老师求助,不像其它机构,通过视频教学,有的甚至学完之后都看不到讲师本人,问点问题都不方便,这就是蓝懿与其它机构的区别,相信在刘国斌老师的细心指导下,每个蓝懿学员都能找到满意的工作,加油!

                                                                  写博客第六十四天;

                                                                              QQ:565803433


0 0