Reputation: 215
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?
Upvotes: 0
Views: 1035
Reputation: 1813
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
Upvotes: 1
Reputation: 21
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?
Upvotes: 0
Reputation: 229
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??
Upvotes: 0
Reputation: 48
Check your image size. If image has big size, table view will not smooth
Upvotes: 0