Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the number of Cells in UITableView

Tags:

I need to loop through all cells in a TableView and set an image for cell.imageView when I press a button. I'm trying to get each cell by

[[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]; 

But I need the count of cells.

How to find the count of cells in TableView?

like image 763
sujith1406 Avatar asked Feb 15 '11 09:02

sujith1406


People also ask

How can we use a reusable cell in UITableView?

For performance reasons, a table view's data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView(_:cellForRowAt:) method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse.

How do I delete a cell in UITableView?

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.

What is Section in UITableView?

UITableView with sections allows us to separate the list into different categories, so the list looks more organized and readable. We can customize sections as per our need, but in this tutorial, we are covering the basic UITableview with sections. Here's is the video if you prefer video over text. Let Create An App.


2 Answers

int sections = [tableView numberOfSections];   int rows = 0;   for(int i=0; i < sections; i++) {     rows += [tableView numberOfRowsInSection:i]; } 

Total Number of rows = rows;

like image 68
Biranchi Avatar answered Oct 06 '22 23:10

Biranchi


the total count of all cells (in a section) should be whatever is being returned by

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

however this method is getting count, you can do it in your own methods also. Probably something like return [myArrayofItems count];

like image 23
Jason Bugs Adams Avatar answered Oct 06 '22 23:10

Jason Bugs Adams