Search code examples
tableviewcelluitableview

How to add image between tableview and cell


how can i add image between tableview and cell? i mean,this image should be under the cell but below the tableview.I add an image but it is not constant when scroll changes its location changes as cell.I want a constant image in tableview,also I add an image self.view but when cell came,image is below of cell


Solution

  • Your question is confusing. As I understand you want to add image as a background of UITableview and that image will not be affected by the scrolling of your table.

    Solution : Set clear background color to your cell and add your image as a background of your Tableview like mentioned below.

    In ViewDidLoad add following Code

    UIImageView *tempImageView = [[UIImageView alloc] 
                                  initWithImage:[UIImage imageNamed:@"iPhone.jpg"]];
    [tempImageView setFrame:self.tableView.frame];
    self.tableView.backgroundView = tempImageView;
    

    Add following method to clear the background color of UITableViewCell.

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        cell.backgroundColor = [UIColor clearColor];
    }
    

    Hope this helps. Happy Coding :)