I am trying to create a UITableView that only displays the number of rows that have data content in them. This is a menu system, and suppose there are 5 choices in the particular menu, I only want to show 5 rows on the screen, with a background image in place of where the empty rows would be (A similar example I guess would be the World Clock). How should I go about this? I’ve trawled around but can’t find anything that helps. Many thanks.
---------------------
Menu Item 1
---------------------
Menu Item 2
---------------------
Rest of view as image
---------------------
Using a grouped table view works, but I don’t really want to use this.
Your UITableView can have a backgroundView. Set it to be a UIImageView, and set it’s frame to the table view’s bounds. This code is untested, but should give you an idea.
EDIT: The above will produce a background like world clock. to make it show below the other cells as a cell, change your data source:
- numberOfRowsInSection:section:should return one more than before.- tableView:canEditRowAtIndexPath:andtableView:canMoveRowAtIndexPath:should returnNOfor this new cell.- (UITableViewCell *)tableView:cellForRowAtIndexPath:needs to create the new cell when the it is asked for, so if you have 5 data cells, the 6th will return:I am not sure if you have to set the image view size, but you do have to set the cell size to take up the remaining space, with something like this in your table view delegate’s
tableView:heightForRowAtIndexPath:for the final row: