1

I am displaying files in a tableview. In cellForRowAtIndexPath, I want to display only certain types of files.

I am doing something like this:

    if (document is folder) {
       display folder details;
    } 
    else (document is not folder) {
       display empty cell;
     }

by doing this i can display empty cells but those are still there(hidden) how to get rid of those rows. see the pic for details.

enter image description here

2
  • Consider using UITableViewStyleGrouped, it should hide empty cells Commented Jan 21, 2013 at 21:11
  • Maybe change the architecture a bit and check the data (on being a folder or not) before you bind to the UITableView? That seems more efficient, based on the information given. Commented Jan 21, 2013 at 21:14

2 Answers 2

2

I think you should rethink the problem, cellForRowAtIndexPath: should never be called for a cell that does not exist. Determine how many folders are available in your data set and return that number in tableView:numberOfRowsInSection:

Then you don't need to worry about hiding it once cellForRowAtIndexPath: is reached because it is a real cell that should be created.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This and answer below helped. :)
1

To 'hide' cells you will need to first create an array of only Folders. Your not really going to hide cells, but rather only include the correct objects in your tables datasource array.

In your viewDidLoad, iterate though your entire documents array and add any Folders to a separate folderArray like so:

_folderArray = [NSMutableArray new];
for(Document *doc in documentsArray)
{
    if(doc is a folder)
    {
        [_folderArray addObject:doc];
    }
}

Use that folderArray in your all of your tableView delegate & datasource methods instead of the documentsArray.

1 Comment

Thanks for pointing me to right direction. I knew i was doing it wrong but couldn't figure out what. :|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.