0

I have a table view with three different custom cells.Each will be loaded from three different cell classes.`

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier1 = @"CellIdentifier";
    static NSString *CellIdentifier2 = @"Cell";
     static NSString *CellIdentifier3 = @"Cell";
    if (indexPath.section == 0)
    { 
         CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];

        if (cell == nil)
        {
            cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier1] autorelease];
        }
        cell.datelabel.text=@"dhhg";
      cell.nameLabel.text=@"shdhsjdj";
    cell.msg.text=@"sdhhhfhjhfj";

       cell.myImageView.image=[UIImage imageNamed:@"sd.png"]; 
        cell.likelabel.text=@"hhhf";

        return cell;

    }
    else 
    {


        Customcellwithimage *cell = (Customcellwithimage *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];

        if (cell == nil)
        {
            cell = [[[Customcellwithimage alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier2] autorelease];
        }
        cell.datelabel1.text=@"sdhkhks";
        cell.nameLabel1.text=@"sdhjkhkshd";
        cell.msg1.text=@"sdsdsd";

        cell.myImageView1.image=[UIImage imageNamed:@"shdjhjhs"]; 
        cell.likelabel1.text=@"sjdh";
        cell.bannerview1.image=[UIImage imageNamed:@"dshjs"]; 

        return cell;
    }

 return Nil;

}

` .This is my code for the design.Can anybody help me in where i am going wrong?

angry_developer
  • 215
  • 1
  • 11

4 Answers4

1

Your lag is probably caused because you are loading from disc in cellForRowAtIndexpath on the main thread. Try to avoid I/o operations on the main thread. Have a look here : loading images from a background thread using blocks

Community
  • 1
  • 1
HeikoG
  • 1,793
  • 1
  • 20
  • 29
0

First of all cellIdentifier2 and cellIdentifier3 have the same value as @"cell".
You have only included 2 conditions, one for section zero and second for others.
You should also mention the condition for using cellIdentifier3.
You haven't mentioned what problem you are having because your code seems not to have any error.
What output do you want? Different cells for different sections??

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
Chirag Bhutani
  • 229
  • 1
  • 8
  • 1
    no.i want to load different cells for different types of responses i got from the webservise.as an expercience i have done this. – angry_developer Nov 01 '12 at 07:49
  • There might be the issue of loading images with larger resolution which might not be needed in the table view cell. Therefore you can have smaller images in your server or in the project. But in case if you don't know the size of the image that you would receive then you can try resizing the image. – Chirag Bhutani Nov 01 '12 at 08:11
0

Check your image size. If image has big size, table view will not smooth

CodeBanBan
  • 48
  • 5
  • you should prepare your image to fit for your size of imageview. before add to your project. ex. 50x50 for normal display and 100x100 for retina display – CodeBanBan Nov 01 '12 at 08:06
0

Your Code seems perfectly fine to me. Avoid using [UIImage imageNamed:@"sd.png"] because it used to create memory issues prior to ios 3.0 however with large images it may still create problems.

You may read:

Does UIImage's imageNamed still cause memory issues on iOS4 for large images?

Community
  • 1
  • 1