0

I have a data model with entity Customer. The Customer has attributes like name, address...etc. One of these attributes is a call back date. I want to load into the table only the Customers with call back date of today. below is the code I have to check to see if the dates are equal and then to create the cell. The problem is when the dates are not equal and it skips the creation of the cell. How do I skip that specific customer and move to the next one?

if(date==date2 && month==month2 && year==year2)
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }


        NSString *string = [NSString stringWithFormat:@"%@ %@", cust.firstName, cust.lastName];
        cell.textLabel.text = string;
        return cell;
    }
return nil;


}
Johnny Cox
  • 1,873
  • 3
  • 17
  • 17
  • While Creating cell check the condition i.e if ( cell== nil and your condition) – Sugan S Dec 28 '12 at 05:39
  • When I do that it returns a blank cell. How do I get it to not return a cell so a blank cell isnt in the table? – Johnny Cox Dec 28 '12 at 06:02
  • `if (condition) { NSString *string = [NSString stringWithFormat:@"%@ %@", cust.firstName, cust.lastName]; cell.textLabel.text = string; return cell;}` try this hope will work – Sugan S Dec 28 '12 at 06:09

1 Answers1

0

I'd take a different route altogether.

Rather than not showing anything in the cell, simply don't provided data for there to even be a cell. You mention that you're using models so I assume you're using core data?

If so, then change your predicate when you fetch your models to ignore all objects that don't meet your criteria. Then you can just show every object in your table as you know that there aren't any you don't want.

Alternatively, fetch everything (if perhaps you're not using core data) then apply a predicate to the array of data you're using and filter it out that way.

PaReeOhNos
  • 4,338
  • 3
  • 30
  • 41
  • How do I use the predicate for only customers with date for today? – Johnny Cox Dec 28 '12 at 05:57
  • You can compound your predicates so that one predicate will get objects where the date is greater than todays date at 0:01am, and less than tonights date at 23:59pm. Take a look at [this answer](http://stackoverflow.com/questions/9401466/nspredicate-and-coredata-decide-if-a-date-attribute-is-today-or-between-las) by yuji which explains it in more detail :) – PaReeOhNos Dec 28 '12 at 06:01