Let's say I have a UITableView which has multiple rows. I want to get all the UITableViewCells as an NSArray at a certain point of time. I have tried
[tableView visibleCells]
but there is a problem with this approach: I can not have all those cells which are not currently in the current screen. So I turned to another approach:
-(NSArray *)cellsForTableView:(UITableView *)tableView { NSInteger sections = tableView.numberOfSections; NSMutableArray *cells = [[NSMutableArray alloc] init]; for (int section = 0; section < sections; section++) { NSInteger rows = [tableView numberOfRowsInSection:section]; for (int row = 0; row < rows; row++) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section]; UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; // **here, for those cells not in current screen, cell is nil** [cells addObject:cell]; } } return cells; }
but seems that this approach still can not get those cells which are not displayed in the screen. Can anyone help me on this?
So, to remove a cell from a table view you first remove it from your data source, then you call deleteRows(at:) on your table view, providing it with an array of index paths that should be zapped. You can create index paths yourself, you just need a section and row number.
The tableview is the instance of the UITableView class, which inherits the UIScrollView class. We will discuss UIScrollView in the upcoming chapters of this tutorial. In iOS applications, whenever we need to display the single column containing vertically scrolling content, we use tableview.
The way I achieve adding spacing between cells is to make numberOfSections = "Your array count" and make each section contains only one row. And then define headerView and its height. This works great.
I don't think thats possible, simply because the tableView doesn't store all cells. It uses a caching mechanism which only stores some cells, that are not visible, for reuse.
Why do you need all cells? Maybe you can achieve, what you're trying to do, otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With