0

I have a UITableView with custom cells,, I want to set background images of those custom cells. The background image of first and the last cell of the UITableView should be different than other cells.

I have used dequeueReusableCellWithIdentifier: to create the cell.

to set the background images of the first cell, I wrote `

 if (indexPath.row==0) {

    cell.cellBackgrounfImage.image=[UIImage imageNamed:@"TopCellImage.png"];
}

`

1) Because of the reusing cell,,, this is going to set middle cell image rarther than the first cell. How can I overcome this problem

2) How to access the last cell of the UITableView to set other image

Please anyone give me a solutions for these 2 questions.

Thanks

iDia
  • 1,397
  • 8
  • 25
  • 44

1 Answers1

1

For Step 1)

When you are scrolling tableview, it will be always reload data. So may be it will generate background image for middle one.

But, if you are set indexpath.row == 0 condition, then it will not affect any row instead of first one.

For Step 2)

You can get values for no of arrays (Array Count). suppose int totalArr = [arr count];

Then apply condition same as first row by,

if(indexpath.row == (totalArr - 1) {

 cell.cellBackgrounfImage.image=[UIImage imageNamed:@"BottomCellImage.png"]; }

So, it will work for last one also. Thanks.

Manann Sseth
  • 2,745
  • 2
  • 30
  • 50
  • Thanks for your reply,, I checked the condition indexpath.row==0. But After 6 cells it going to apply the 1st cell image to the 7th cell also. So how can it avoid. And thanks for step2). I will try it. – iDia Aug 29 '12 at 02:42