i have to print date on lable .The date is coming from database it show proper But problem is i have to compare database date with current date .If database date is smaller then current date then lable should print string @“Due”,otherwise print date like this:03/05/2012. this code which i am doing in my custom cell class i writen this code in method which i pass in controller class when i scroll my tableview then value is change where i am wrong please help me
- (void) updateContent: (Tasksmodal*) taskobject{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSString* duedate = [dateFormat stringFromDate:taskobject.DueDate];
NSDate *currentdate;
currentdate=[NSDate date];
//NSDateFormatter *dateFormat1 = [[NSDateFormatter alloc] init];
//[dateFormat1 setDateFormat:@"dd/MM/yyyy"];
NSString* duedate1 = [dateFormat stringFromDate:currentdate];
if ([currentdate compare:taskobject.DueDate]!=NSOrderedDescending) {
DateLable.text=@"Due";
DateLable.textColor=[UIColor redColor];
}
else{
DateLable.text=duedate;
DateLable.textColor=[UIColor blackColor];
}
}
in my controller class .m // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TasksList * cell =(TasksList*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[TasksList alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
//[[[cell contentView] subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];
taskobject=(Tasksmodal*)[self.lstTasks objectAtIndex:indexPath.row];
[cell updateContent:taskobject];
return cell;
}