UITableView (Controller) - Hide blank lines

I am trying to create a UITableView that only displays the number of rows that contain data content. This is a menu system, and suppose there are 5 options in a particular menu, I want to show only 5 lines on the screen, with a background image instead of where the empty lines will be. (A similar example, I think, would be the World Clock). How can I do it? I traded, but I can’t find anything that will help. Many thanks.

 --------------------- Menu Item 1 --------------------- Menu Item 2 --------------------- Rest of view as image --------------------- 

Using a grouped table view works, but I really don't want to use this.

+6
objective-c iphone uitableview
source share
1 answer

Your UITableView may have a backgroundView. Set it as a UIImageView and set the frame for it in the frame of the table. This code has not been verified, but should give you an idea.

 UIImage * img = [UIImage imageNamed:@"myImage.jpg"]; UIImageView * imgView = [[UIImageView alloc] initWithImage:img]; imgView.frame = myTableView.bounds; myTableView.backgroundView = imgView; 

EDIT: The above will create a background similar to a world clock. so that it appears under other cells as a cell, change the data source:

- numberOfRowsInSection:section: should return one more than before. - tableView:canEditRowAtIndexPath: and tableView:canMoveRowAtIndexPath: should return NO for this new cell. - (UITableViewCell *)tableView:cellForRowAtIndexPath: you need to create a new cell when it is requested, so if you have 5 data cells, the sixth will be returned:

 UITableViewCell * cell = //create your cell //change the height to match the remaining space UIImage * img = [UIImage imageNamed:@"myImage.jpg"]; UIImageView * imgView = [[UIImageView alloc] initWithImage:img]; cell.backgroundView = imgView; 

I'm not sure that you need to set the image size, but you need to set the cell size to take up the remaining space, with something like this in the delegate view of the t27> table for the last row:

 //if final row return myTableView.bounds.size.height - 16.0 * myData.count; //modify from the default 16.0 as needed. 
+4
source share

All Articles