This is my cellForRowAtIndexPath
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(12,11,320,40)];
label.text = [animalArray objectAtIndex:indexPath.row];
[cell addSubview:label];
In the animalArray i have the following items,
Lion, Dog, Cat, Zebra, Donkey, Monkey...
The problem is;
1.) When i add the label inside the if (cell == nil) { condition i see repeated records. like Lion, Dog, Cat, Zebra and then again Lion as i scroll down.
2.) When i add it outside the if (cell == nil) { the records overlap as i scroll.
I understand that this is because the cell is reusing its self, and i am creating a Label each time (so it gets overlapped). I don’t know how to fix this issue programatically. Can someone please help me.
EDIT:
I have just displayed 1 label here. but i have more than one label to display. and also some UIComponants.
I writing this code without checking syntax: