0

I am trying to add a background image to the table view. My code for this is here:

UIImageView *backImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"background.png"]];
[backImageView setFrame:CGRectMake(0, 0, 768, 1024)];
[self.view addSubview:backImageView];

UITableView *aTableView=[[UITableView alloc]initWithStyle:UITableViewStyleGrouped];
[aTableView setFrame:CGRectMake(0, 0, 768, 1024)];

[aTableView setDelegate:self];
[aTableView setDataSource:self];
[aTableView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:aTableView];
[aTableView release];

I am not getting a background image, and I don't want to use AppDelegate. Anybody help me.

AWrightIV
  • 553
  • 7
  • 15
sny
  • 41
  • 4

2 Answers2

1

Your question is already answered in this Stack Overflow question. The solution in the referenced question is less code than you are using here.

Community
  • 1
  • 1
Walter
  • 5,867
  • 2
  • 30
  • 43
0

@sny i suggest you to try this .....give the imageview to the background of the view

In -

(void)viewDidLoad {
    [super viewDidLoad];

self.view.backgroundColor = [UIColor clearColor]; //this will clear you views background

UIImageView *Image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
        Image.image = [UIImage imageNamed:@"background.png"];
        [self.view addSubview:Image];
        [Image release];

//Now you have the image in the background of the view

[self.view insertSubview:Image atIndex:0]; //this will set imageviews index to zero

}

Now you will always get the image in the background of your TableView But also make sure that you had clear the backgroung of your TableView

//Now write code for your table view as u had written above in your class

I Hope this will help you .....Good Luck!!!

Sudhanshu
  • 3,950
  • 1
  • 19
  • 18