Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xaphann

macrumors newbie
Original poster
Oct 22, 2011
11
0
Have an UITableViewController with a custom cell and want to add an image "behind" it. Let me try to describe it; there is enough room for six cells to be on the screen at a time. If there is less then 6 then below the last cell the image should appear. The image should not scroll with the cells, it is designed to take up the full screen of the iphone (mean 360x470 pixels). No blank cells should appear.

In the viewDidLoad;
Code:
self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backGround.png"]];
self.tableView.backgroundColor = [UIColor clearColor];

Then in the cellForRowAtIndexPath method;
Code:
cell.accessoryView.backgroundColor = [UIColor redColor];

note: red is not the final color of the cell, the background will be an image. The red is for testing (and the cell image is not done :D ).

The problem is that with this code the cells appear to be transparent (you can see the background image on cells that contain data), there are blank cells displayed (so for example if only 2 cell have data 4 blank cells are also displayed) and the image is not stationary it scrolls (therefore it loops and the image is not designed to loop).

FYI the numberOfRowsInSection is set with this;
Code:
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];

thanks for the help
 

dantastic

macrumors 6502a
Jan 21, 2011
572
678
First of all, UITableViewController can't do what you want to do. UITableviewcontroller is evil, stay away from it. Createa UIViewController, drop a UITableview onto it and create a property and connect delegates.

This way you will be able to assign a view with a clear color to the background view and also you can add a uiimageview under your uitableview.
 

xaphann

macrumors newbie
Original poster
Oct 22, 2011
11
0
Really? There is no better answer? That means a lot of re-doing work
 

xaphann

macrumors newbie
Original poster
Oct 22, 2011
11
0
Ok, it was not as much work as I thought but I am still getting the same results. So this is what I did, created a new UIViewController, and re-did the code to point to UITableView in the UIViewController. The data and all functionality works. Then add an UIImage behind the UITableView. Running the app at this point will result in nothing showing up. Adding this code makes the image appear;
Code:
self.tableView.backgroundColor = [UIColor clearColor];
Issue is that just like before the image scrolls with the table and blank cells appear.
 
Last edited:

xaphann

macrumors newbie
Original poster
Oct 22, 2011
11
0
Fixed it!

For those that care here are the basic steps. Add the UIImage to the back of the view controller. Then add this code to your viewDidLoad;
Code:
tableView.backgroundColor = [UIColor clearColor];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

Then add the following method;
Code:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
	//Set a color
        cell.backgroundColor = [UIColor whiteColor];
	//Set an image
        //cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myCellImage.png"]];
	
}

Thank for the help and pointing me in the right direction!
 

MattInOz

macrumors 68030
Jan 19, 2006
2,760
0
Sydney
Not sure if this is to late to be helpful, I know I hit the same issue a while back.

In myTableViewController and within the -viewDidLoad method I have the these two lines of code and it works.

Code:
UIImageView *boxBackView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TextureBoxboard.jpg"]];
[self.tableView setBackgroundView:boxBackView];

but it's only visible on screen if there are no cells on top of it or the cell background colour is set clear.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.