1.NSDate = year, month, day, etc. In the recent project, to get the data of the current time, such as year, month, day, etc., search finally get a method as follows:

- (void)setDateArray
{
    NSDate *dateNow;
    for (int i = 0; i<7; i++) {
        dateNow = [NSDate dateWithTimeIntervalSinceNow:i*24*60*60];
        NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
        NSDateComponents *comps = [[NSDateComponents alloc]init];
        NSInteger unitFlags = NSYearCalendarUnit|NSDayCalendarUnit|NSWeekdayCalendarUnit|NSHourCalendarUnit |NSMonthCalendarUnit;
        comps = [calendar components:unitFlags fromDate:dateNow];
        long day = [comps day];
        NSUInteger month = [comps month];
        NSString *dateStr = [NSString stringWithFormat:@"%ld month % LD day",month,day]; [_dateArray addObject:dateStr]; }}Copy the code

Output _dataArray is available

12 * * * * * * * * * * 14 * * * *, * * * * * * * * * * * * 15 * * * *, * * * * * * * * * * * * 16 * * * *, * * * * * * * * * * * * 17 * * * *, * * * * * * * * * * * * * * * * * * 18 days **12**** month ****19**** day **** 12 port month ****20**** day **Copy the code
  1. Some minor issues with Xcode 7 tableView

In xcode7, there are some partition lines that cannot be hidden:

-(void)layoutSubviews{
      [super layoutSubviews]; 
       self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
Copy the code
  1. The reloadData refresh fails
[tableView reloadData]
Copy the code

Invalid. A row of cells has been changed but cannot be refreshed. [tableView reloadData] [tableView reloadData]

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
Copy the code

4. Use bugtags to test bugs

** @param startDate startDate * @param endDate endDate ** @returnReturn the number of hours between two time periods */ + (NSString *)getStartTime:(NSString *)startDate endTime:(NSString *)endDate {NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormattersetDateFormat:@"HH:mm"];
    
    NSDate *date1 = [dateFormatter dateFromString:startDate];
    NSDate *date2 = [dateFormatter dateFromString:endDate];
    
    NSTimeInterval time = [date2 timeIntervalSinceDate:date1];
    float hours = (float)time/3600;
    return [NSString stringWithFormat:@"%.2f",hours]; } /** * Determine the number of weeks in a period (e.g., determine the number of Fridays between January 29 and February 12) ** @param startDate Start time * @param endDate end time * @param weekStr determine the day of the week * * @returnNsstring is a number */ - (nsstring *)featureWeekdayWithDate:(nsstring *)startDate endStart:(nsstring *)endDate weekStr:(NSString *)weekStr { NSInteger dayIndex = 0;if ([weekStr isEqualToString:@"Sunday"]) {
        dayIndex = 7;
    }
    if ([weekStr isEqualToString:@"Monday"]) {
        dayIndex = 1;
    }
    if ([weekStr isEqualToString:@"Tuesday"]) {
        dayIndex = 2;
    }
    if ([weekStr isEqualToString:@"Wednesday"]) {
        dayIndex = 3;
    }
    if ([weekStr isEqualToString:@"Thursday"]) {
        dayIndex = 4;
    }
    if ([weekStr isEqualToString:@"Friday"]) {
        dayIndex = 5;
    }
    if ([weekStr isEqualToString:@"Saturday"]) {
        dayIndex = 6;
    }
    
    long days = [[MyUtil getStartTime:startDate endTime:endDate] integerValue]; days++; NSInteger fullIndex = days>=7? days/7 : 0; long day = days >= 7 ? days % 7 : days; NSInteger flag = 0;for (int i = 0; i< day; i++) {
        NSDate *date = [NSDate dateWithString:startDate format:@"yyyy-MM-dd"];
        long week = ([date weekday]+i)%7;
        switch (week) {
            case 1:
                if (dayIndex == 7) {
                    flag++;
                }
                break;
            case 2:
                if (dayIndex == 1) {
                    flag++;
                }
                break;
            case 3:
                if (dayIndex == 2) {
                    flag++;
                }
                break;
            case 4:
                if (dayIndex == 3) {
                    flag++;
                }
                break;
            case 5:
                if (dayIndex == 4) {
                    flag++;
                }
                break;
            case 6:
                if (dayIndex == 5) {
                    flag++;
                }
                break;
            case 7:
                if (dayIndex == 6) {
                    flag++;
                }
                break;
            default:
                break; }}return [NSString stringWithFormat:@"%d",fullIndex+flag];
}
Copy the code

Set a UIView background image: Recommended

 NSString *path = [[NSBundlemainBundle]pathForResource:@"image"ofType:@"jpg"];      
 UIImage *image = [UIImageimageWithContentsOfFile:path];
 self.view.layer.contents = (id)image.CGImage;
Copy the code

Image cache Depending on whether the created object is cached in system memory, there are two optional methods for creating UIImage objects:

Cache: + imageNamed:, just pass in the file name. The extension (optional) is sufficient. No cache: + imageWithContentsOfFile:, must pass in the full name of the file (full path + filename).

The image resources in assets.xcassets can only be loaded using the imageNamed: method. The image path cannot be obtained through the pathForResource:ofType of the NSBundle. Therefore, assets. xcassets are only suitable for storing pictures that are commonly used by the system and occupy little memory. The imageNamed: method also loads image resources in the root directory. To load an image without caching using the imageWithContentsOfFile: method, you must place the image resource in the root directory.