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

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
Hi,

I seem to be having a really strange problem. As you can see in the code below, I have an image view that is supposed to show up in the background of a UITableView when the view controller's view is loaded. For some reason, whether the background image view creation code is placed in viewDidLoad or viewDidAppear, the background image won't show until after I tap one of the table view's cells.

Here's the code:

Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *roadImagePath = [[NSBundle mainBundle] pathForResource:@"Word Family App Screen Blank Road" ofType:@"png"];
    CGRect tableViewFrame = [self.tableView frame];
    CGRect roadViewFrame = (CGRect){CGPointZero,tableViewFrame.size};
    roadViewFrame.size.height = 300;
    UIImage *image = [UIImage imageWithContentsOfFile:roadImagePath];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [imageView setFrame:roadViewFrame];
    [imageView setUserInteractionEnabled:false];
    [self.tableView setBackgroundView:imageView];

Please help, and thank you!
 
Please help me!

I have two ideas, neither of which are particularly desirable:

1) Use a NIB file & a subclass of UITableView
2) Create a UIView, put the table view & an image view in that view, and send the image view to the back.
 
Would you mind posting the contents of your didSelectRowAtIndexPath: method?
Not quite sure if it'll help, but here it is:
Code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *segueIdentifier;
    NSInteger row = [indexPath row];
    NSInteger section = [indexPath section];
    if (section < [[self elements] count] - 1)
    {
    switch (row) {
        case 0:
            segueIdentifier = @"xxxxSegue";
            break;
        case 1:
            segueIdentifier = @"xxVCSegue";
            break;
        default:
            break;
    }
    }
    else
    {
        segueIdentifier = @"xxxSegue";
    }
    [self performSegueWithIdentifier:segueIdentifier sender:[NSNumber numberWithInteger:[indexPath section]]];
}
 
It might help if that's when your tableView background image starts displaying correctly. I thought you might be doing something in that method that could be done in viewDidLoad or viewDidAppear instead, but from what you've posted, nothing like that stands out.

I see you are using storyboards, which I have not used myself. The question I would be asking myself is this:

Is there anything about a storyboard that would cause you not to be able to manipulate the tableView programmatically?

Code:
[self.tableView setBackgroundView:imageView];

I'm not aware of any reason why you shouldn't be able to, but like I said I haven't used storyboards.
 
It might help if that's when your tableView background image starts displaying correctly. I thought you might be doing something in that method that could be done in viewDidLoad or viewDidAppear instead, but from what you've posted, nothing like that stands out.

I see you are using storyboards, which I have not used myself. The question I would be asking myself is this:

Is there anything about a storyboard that would cause you not to be able to manipulate the tableView programmatically?

Code:
[self.tableView setBackgroundView:imageView];

I'm not aware of any reason why you shouldn't be able to, but like I said I haven't used storyboards.

To answer your question, I am not aware of anything that would prevent me from accomplishing my goal. Also, I tried that line of code, but that didn't work. Also, the cells are not opaque (at least, they're not supposed to be).

Edit: I think the problem was with the image itself. You see, the image was mostly white. But I just did some cropping. Then I could kind of see what I wanted to see.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.