解决dashboard卡的有关问题
解决dashboard卡的问题
//Edit by nanoha UIView *cellDataView; TWBMDrawGraph *section1View; TWBMDrawSleepTimeBarGraph *section2View; TWBMDrawWeightGraph *section3View; TWBMDrawCalorieConsumptionGraph *section4View; TWBMDrawMealBarGraph *section5View; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellId = @"Cell"; TWBMCardTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; for (UIView * view in [cell.contentView subviews]) { [view removeFromSuperview]; } // if (!cell) { cell = [[TWBMCardTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; // } //設定によって表示順番をかえる ★TBD //それぞれのWidget作成 UIView * makeWidgetView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDGET_WIDTH, WIDGET_HEIGHT)]; //下記でそれぞれにあったViewを表示生成機能をコールして作成 ★TBD // if (indexPath.section == 0) { ★ // TWBMDrawGraph * drawGraph = [[TWBMDrawGraph alloc]initWithFrame:makeWidgetView.frame]; // // [cell.contentView addSubview:drawGraph]; // // } else if (indexPath.section == 1) { // // } else if (indexPath.section == 2) { // TWBMDrawWeightGraph * weightGraph = [[TWBMDrawWeightGraph alloc]initWithFrame:makeWidgetView.frame]; // [cell.contentView addSubview:weightGraph]; // // } else if (indexPath.section == 3) { // // } // if(indexPath.section == 0) { //////////////20140904 if(cellDataView == nil){ cellDataView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDGET_WIDTH, 100)]; cellDataView.backgroundColor = [UIColor whiteColor]; UIView * pieChartView = [[UILabel alloc]initWithFrame:CGRectMake(PIECHARTLAVEL_WIDTH_MARGIN, PIECHARTLAVEL_HEIGHT_MARGIN, 54, 54)]; /////////////20140905 NSInteger dayCnt = indexPath.row; if (dayCnt != 0) { dayCnt = dayCnt * -1; } NSDate * day = [NSDate dateWithTimeIntervalSinceNow:dayCnt * 24 * 60 * 60]; NSDateFormatter *outputFormatter = [[NSDateFormatter alloc]init]; [outputFormatter setDateFormat:@"yyyyMMdd"]; NSDateComponents *components = [[NSDateComponents alloc]init]; NSString * todayStr = [NSString stringWithFormat:@"%@",[outputFormatter stringFromDate:day]]; components.year = [[todayStr substringToIndex:4]integerValue] ; components.month = [[todayStr substringWithRange:NSMakeRange(4, 2)]integerValue] ; components.day = [[todayStr substringWithRange:NSMakeRange(6, 2)]integerValue] ; TWBMManageDatabase * dbManager; dbManager = [[TWBMManageDatabase alloc]init]; [pieChartView addSubview:[[TWBMDrawCircleGraph alloc]initWithFrame:CGRectMake(0, 0, 54, 54) archievementValue:[dbManager getArchievement:components]]]; UILabel * dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 10, 160, 20)]; NSCalendar * cal = [NSCalendar currentCalendar]; NSDateComponents * weekCon = [cal components:NSCalendarUnitWeekday fromDate:day]; NSString *const array[] = {nil,@"SUN",@"MON",@"TUE",@"WED",@"THU",@"FRI",@"SAT"}; NSInteger week = weekCon.weekday; if (week > 7) { week = 0; } NSString *weekStr = array[week]; [outputFormatter setDateFormat:@"yyyy/M/d"]; dateLabel.text = [NSString stringWithFormat:@"%@ (%@)",[NSString stringWithFormat:@"%@",[outputFormatter stringFromDate:day]],weekStr]; dateLabel.font =[UIFont systemFontOfSize:10.5f]; dateLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; ////////////////////// UILabel * itemsLabel = [[UILabel alloc]initWithFrame:CGRectMake(85, 35, WIDGET_WIDTH, 20)]; // WERAM1100-8 [057]M-1画面の表示項目と文言修正 //itemsLabel.text = @"歩数 消費カロリー 体重"; itemsLabel.text = @"歩数 消費カロリー 睡眠時間"; itemsLabel.font =[UIFont systemFontOfSize:10.5f]; itemsLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; // 上限500000のため /* //UILabel * stepDataLabel = [[UILabel alloc]initWithFrame:CGRectMake(75 , 55, 55, 34)]; UILabel * stepDataLabel = [[UILabel alloc]initWithFrame:CGRectMake(67, 55, 75, 34)]; //stepDataLabel.text = @"500000"; stepDataLabel.text = [self arrayDataCounts:[dbManager getSteps:components type:0] dataType:DATA_TYPE_STEP]; stepDataLabel.font =[UIFont systemFontOfSize:18.0f]; stepDataLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; stepDataLabel.textAlignment = NSTextAlignmentLeft; //stepDataLabel.textAlignment = NSTextAlignmentRight; UILabel * stepDataUnitLabel = [[UILabel alloc]initWithFrame:CGRectMake(70 + 55, 55, 55, 34)]; stepDataUnitLabel.text = @"歩"; stepDataUnitLabel.font =[UIFont systemFontOfSize:16.0f]; stepDataUnitLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; */ UILabel * stepDataLabel = [[UILabel alloc]initWithFrame:CGRectMake(69, 55, 60, 34)]; //stepDataLabel.text = @"500000"; stepDataLabel.text = [self arrayDataCounts:[dbManager getSteps:components type:0] dataType:DATA_TYPE_STEP]; stepDataLabel.font =[UIFont systemFontOfSize:17.0f]; stepDataLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; stepDataLabel.textAlignment = NSTextAlignmentRight; UILabel * stepDataUnitLabel = [[UILabel alloc]initWithFrame:CGRectMake(72 + 55, 55, 55, 34)]; stepDataUnitLabel.text = @"歩"; stepDataUnitLabel.textAlignment = NSTextAlignmentLeft; stepDataUnitLabel.font =[UIFont systemFontOfSize:16.0f]; stepDataUnitLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; // WERAM1100-8 [057]M-1画面の表示項目と文言修正 睡眠時間修正 //UILabel * calDataLabel = [[UILabel alloc]initWithFrame:CGRectMake(150, 55, 55, 34)]; UILabel * calDataLabel = [[UILabel alloc]initWithFrame:CGRectMake(141, 55, 55, 34)]; // 上限50000のため //calDataLabel.text = @"50000"; calDataLabel.text = [NSString stringWithFormat:@"%ld",(long)([[self arrayDataCounts:[dbManager getCalorieConsumption:components type:0] dataType:DATA_TYPE_CALORIECONSUMPTION] integerValue]/1000)]; calDataLabel.font =[UIFont systemFontOfSize:17.0f]; calDataLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; calDataLabel.textAlignment = NSTextAlignmentRight; // WERAM1100-8 [057]M-1画面の表示項目と文言修正 睡眠時間修正 // UILabel * calDataUnitLabel = [[UILabel alloc]initWithFrame:CGRectMake(150 + 55, 55, 55, 34)]; UILabel * calDataUnitLabel = [[UILabel alloc]initWithFrame:CGRectMake(141 + 55, 55, 55, 34)]; calDataUnitLabel.text = @"kcal"; calDataUnitLabel.font =[UIFont systemFontOfSize:15.0f]; calDataUnitLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; // WERAM1100-8 [057]M-1画面の表示項目と文言修正 睡眠時間修正 /* UILabel * weightDataLabel = [[UILabel alloc]initWithFrame:CGRectMake(225, 55, 55, 34)]; weightDataLabel.text = [self weightGetArray:[dbManager getWeight:components type:0 today:[NSDate date]]]; weightDataLabel.font =[UIFont systemFontOfSize:18.0f]; weightDataLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f];; weightDataLabel.textAlignment = NSTextAlignmentRight; // WERAM1100-8 [057]M-1画面の表示項目と文言修正 UILabel * weightDataUnitLabel = [[UILabel alloc]initWithFrame:CGRectMake(225 + 55, 55, 55, 34)] ; weightDataUnitLabel.text = @"kg"; weightDataUnitLabel.font =[UIFont systemFontOfSize:16.0f]; weightDataUnitLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; */ UILabel *todaySleepDataLabel = [[UILabel alloc]initWithFrame:CGRectMake(215, 55, 100, 34)]; todaySleepDataLabel.font = [UIFont systemFontOfSize:16.0f]; todaySleepDataLabel.textColor = [UIColor colorWithRed:121.0f / 255.0f green:121.0f / 255.0f blue:121.0f / 255.0f alpha:1.0f]; todaySleepDataLabel.textAlignment = NSTextAlignmentRight; //目標睡眠時間取得 //tergetSleepTime = [dbManager getTargetSleepTime]; //睡眠時間取得 NSInteger todaySleepTime = [self arraySleepDataCounts:[dbManager getSleepTime:components type:TWBMMANAGEDATABASE_TYPE_PER_DAY]]; // NSInteger todaySleepTime = [dbManager getSleepTime:components type:TWBMMANAGEDATABASE_TYPE_PER_DAY].count; NSString *sleepStr; if (todaySleepTime == 0) { sleepStr = [NSString stringWithFormat:@"%d時間%d分",0,0]; }else { sleepStr = [NSString stringWithFormat:@"%ld時間%ld分",todaySleepTime/60,todaySleepTime%60]; } todaySleepDataLabel.text = sleepStr; [cellDataView addSubview:dateLabel]; [cellDataView addSubview:pieChartView]; [cellDataView addSubview:itemsLabel]; [cellDataView addSubview:stepDataLabel]; [cellDataView addSubview:stepDataUnitLabel]; [cellDataView addSubview:calDataLabel]; [cellDataView addSubview:calDataUnitLabel]; // WERAM1100-8 [057]M-1画面の表示項目と文言修正 //[cellDataView addSubview:weightDataLabel]; //[cellDataView addSubview:weightDataUnitLabel]; [cellDataView addSubview:todaySleepDataLabel]; } [cell.contentView addSubview:cellDataView]; ////////////////////////////// } // if(indexPath.section == 0) else if(indexPath.section == 1) { if(section1View == nil){ section1View = [[TWBMDrawGraph alloc]initWithFrame:makeWidgetView.frame]; } [cell.contentView addSubview:section1View]; } // else if (indexPath.section == 1) else if (indexPath.section == 2) { if(section2View == nil){ section2View = [[TWBMDrawSleepTimeBarGraph alloc]initWithFrame:makeWidgetView.frame]; } [cell.contentView addSubview:section2View]; } // else if (indexPath.section == 2) else if (indexPath.section == 3) { if(section3View == nil){ section3View = [[TWBMDrawWeightGraph alloc]initWithFrame:makeWidgetView.frame]; } [cell.contentView addSubview:section3View]; } // else if (indexPath.section == 3) else if (indexPath.section == 4) { if(section4View == nil){ section4View = [[TWBMDrawCalorieConsumptionGraph alloc] initWithFrame:makeWidgetView.frame]; } [cell.contentView addSubview:section4View]; } /////////////20140905 else if (indexPath.section == 5) { if(section5View == nil){ section5View = [[TWBMDrawMealBarGraph alloc]initWithFrame:makeWidgetView.frame]; } [cell.contentView addSubview:section5View]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } //End by nanoha