- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellTableIdentifier = @"CellTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
if (cell == nil) {
CGRect cellFrame = CGRectMake(0,0,300,65);
cell = [[[UITableViewCell alloc] initWithFrame: cellFrame
reuseIdentifier:CellTableIdentifier] autorelease];
CGRect projectValueRect = CGRectMake(12,44,100,17);
UILabel *projectValue = [[UILabel alloc] initWithFrame:projectValueRect];
projectValue.textAlignment = UITextAlignmentLeft;
projectValue.backgroundColor=[UIColor clearColor];
projectValue.textColor=[UIColor whiteColor];
// projectValue.font = [UIFont boldSystemFontOfSize:12];
projectValue.tag = kProjectValueTag;
[cell.contentView addSubview:projectValue];
[projectValue release];
CGRect RTRect = CGRectMake(90,45,60,15);
UILabel *RTRectLbl = [[UILabel alloc] initWithFrame:RTRect];
RTRectLbl.textAlignment = UITextAlignmentLeft;
RTRectLbl.text = @"R.Time:";
RTRectLbl.backgroundColor=[UIColor clearColor];
RTRectLbl.textColor=[UIColor whiteColor];
//RTRectLbl.font = [UIFont boldSystemFontOfSize:14];
[cell.contentView addSubview: RTRectLbl];
[RTRectLbl release];
CGRect timeValueRect = CGRectMake(150,45,60,15);
UILabel *timeValue = [[UILabel alloc] initWithFrame:timeValueRect];
timeValue.backgroundColor=[UIColor clearColor];
timeValue.textColor=[UIColor whiteColor];
timeValue.tag = kTimeValueTag;
[cell.contentView addSubview:timeValue];
[timeValue release];
CGRect nameValueRect = CGRectMake(10,9,100,15);
UILabel *nameValue = [[UILabel alloc] initWithFrame:nameValueRect];
nameValue.backgroundColor=[UIColor clearColor];
nameValue.textColor=[UIColor whiteColor];
nameValue.tag = kNameValueTag;
[cell.contentView addSubview:nameValue];
[nameValue release];
CGRect DueDate = CGRectMake(160,9,150,15);
UILabel *dueDate = [[UILabel alloc] initWithFrame:DueDate];
dueDate.backgroundColor=[UIColor clearColor];
dueDate.textColor=[UIColor whiteColor];
dueDate.tag = kDueValueTag;
[cell.contentView addSubview:dueDate];
[dueDate release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(cellClick:)
forControlEvents:UIControlEventTouchDown];
button.tag=indexPath.row;
[button setBackgroundImage:[UIImage imageNamed:@"detail.png"] forState:UIControlStateNormal];
//[button setTitle:@">>" forState:UIControlStateNormal];
button.frame = CGRectMake(260, 45.0, 45.0, 45.0);
[cell.contentView addSubview:button];
}
// Set up the cell...
NSLog(@"%d",indexPath.row);
Tasks *taskDetails=[allTasks objectAtIndex:indexPath.row];
Projects *projrctDetails=[allProjects objectAtIndex:indexPath.row];
NSLog(@"%@",projrctDetails.project_title);
UILabel *name = (UILabel *)[cell.contentView viewWithTag:kNameValueTag];
name.text = taskDetails.task_title;
UILabel *Duedate = (UILabel *)[cell.contentView viewWithTag:kDueValueTag];
Duedate.text = taskDetails.task_due_date;
UILabel *projectText = (UILabel *)[cell.contentView viewWithTag:kProjectValueTag];
projectText.text = projrctDetails.project_title;
UILabel *timeTag = (UILabel *)[cell.contentView viewWithTag:kTimeValueTag];
NSTimeInterval lastDiff = [[self.dateFormatter dateFromString:taskDetails.task_due_date] timeIntervalSinceNow];
NSDate *now = [NSDate date];
NSString *dateString = [self.dateFormatter stringFromDate:now];
NSTimeInterval todaysDiff = [[self.dateFormatter dateFromString:dateString] timeIntervalSinceNow];
NSTimeInterval dateDiff = lastDiff - todaysDiff;
div_t h = div(dateDiff, 3600);
int hours = h.quot;
// Divide the remainder by 60; the quotient is minutes, the remainder
// is seconds.
div_t m = div(h.rem, 60);
int minutes = m.quot;
timeTag.text = [NSString stringWithFormat:@" %d:%d",hours,minutes];
// [cell setBackgroundColor:[UIColor colorWithRed:3/255.0f green:130/255.0f blue:242/255.0f alpha:1.0]];
return cell;
}
No comments:
Post a Comment