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?
The tableview is the instance of the UITableView class, which inherits the UIScrollView class.
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.
Returns the number of rows (table cells) in a specified section.
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.
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
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