Question: I have a dynamic populated list. I am trying to have it return nothing if a variable is a certain value.

Here is what I am doing:

```
/* FIRST VALIDATE TIME LEFT TO MAKE SURE IT STILL EXIST */
    NSString *check = [self.googlePlacesArrayFromAFNetworking[indexPath.row] objectForKey:@"time_left"];
    if(![check isEqualToString:@"expired"])
    {
        return cell;
    }
    else
    {
        return NULL;
    }

```

Now if `expired` exist than it returns `NULL` but that does not work. It crashes with the following error: 

`'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'`

Not sure how I can fix this, suggestions and thoughts?

David

UPDATE:

`cell`:

```
static NSString *CellIdentifier = @"timelineCell";
    FBGTimelineCell *cell = (FBGTimelineCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell = [[FBGTimelineCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [cell initTimelineCell];

```

Answer: 
Your data source must return consistent values across all of its methods. The number of rows in your tableView is controlled by the return value from `numberOfRowsInSection` and `cellForRowAtIndexPath` must return a valid cell for each row.

Validation and modification of the data in the data source must be performed outside of `cellForRowAtIndexPath` and `[tableView reloadData]` or `[tableView deleteRowsAtIndexPaths]` called to update the table display

**Update**

It is hard to provide an example without understanding what is driving the "expired" behaviour - Is this data that is retrieved from the web service or is it the result of information ageing after it is retrieved. If the former then I would suggest that you transfer the data from the web service result array into an array that drives the tableview and filter the expired data while you are copying it. If you need to periodically scan for expired data then you can use something like the following - 

You would need to have something, such as an `NSTimer` trigger this method periodically, or if you are re-fetching data from the network, that could be the trigger to run this method - 

```
-(void)expireData
{
   for (int i=0;i<self.googlePlacesArrayFromAFNetworking.count;++i) {
       NSDictionary *dict=[self.googlePlacesArrayFromAFNetworking objectAtIndex:i];

       if ([[dict objectForKey:@"time_left"] isEqualToString:@"expired"])
       {
           [self.googlePlacesArrayFromAFNetworking removeObjectAtIndex:i];

           [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:i inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
            --i;      // Array is now one element smaller;

       }
   }
}

```

Note that this method modifies the self.googlePlacesArrayFromAFNetworking array. If this is unacceptable then you need to copy this array to another array to drive the `UITableView`.

Another approach is to scan the array in `numberOfRowsInSection` and work out how many non-expired elements there are and return that. Then in `cellForRowAtIndexPath` you need to scan forward through the array to find the next non-expired element; This is pretty messy though because your indexPath rows and your array indices will be out of sync.
It depends on what you want. There are two options:

1. If you want your table view to have empty rows for the data that are expired, you need to configure and return a blank cell.
2. If you want those cells to be missing, you need to return the correct number of rows for `-tableView:numberOfRowsInSection` (that is, subtract out the number of expired rows in your calculations before returning from that method). Then, your data source will never be asked for a cell for that index path.

**Update:** by the way, you should return `nil`, not `NULL`, when the parameter is expecting an Objective-C object. `nil` is equivalent to (id)0, whereas `NULL` is equivalent to `(void *)0`. [[source](http://nshipster.com/nil/)]