Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a Row count from a UITableView

I have a tableview I'd like to customize based on how many rows it has.

If it has no rows, I'd like the background image to prompt the user to add content. If it has 1 or more rows, I'd like it to have a different background image, in order to display the content.

I'm using a fetched results controller to populate my tableview, by the way.

Any ideas?

like image 748
monotreme Avatar asked Dec 03 '09 01:12

monotreme


People also ask

What class does UITableView inherit from?

The tableview is the instance of the UITableView class, which inherits the UIScrollView class.

What is a UITableView?

UITableView manages the basic appearance of the table, but your app provides the cells ( UITableViewCell objects) that display the actual content. The standard cell configurations display a simple combination of text and images, but you can define custom cells that display any content you want.

What is numberOfRowsInSection?

Returns the number of rows (table cells) in a specified section.


2 Answers

Well this is generally very easy to accomplish as you need only to have UITableView properly delegated to your ViewController with appropriate delegate methods included in your .m file.

Then you can anywhere get row count like this:

[tablePropertyName numberOfRowsInSection:SECTION_NUMBER];

where section number is 0 for first section, 1 for second, etc.

like image 131
ArnieX Avatar answered Sep 21 '22 06:09

ArnieX


In Swift, you can get the UITableView rows count by

yourTableViewName.numberOfRows(inSection: Int)

example:

yourTableViewName.numberOfRows(inSection: 0) // returns rows count in section 0   
like image 40
PAC Avatar answered Sep 18 '22 06:09

PAC