I have set the size of the tableView that I show as the popoverController as 4*rowheight. And I am using 12cells in the tableView. Each cell contains an image and a label. I can see all the cells by scrolling. Upto 5th cell its ok. After th2 5th cell, the label and the image that I am using in the first four cells are being repeated for the remaining cells. And If I select the cell, the result is accurately shown.
But when I again take the tableView, the image and labels are not accurate even for the first 5 cells. All are changed but the selection is giving the correct result. Can anyone help me??
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [self tableviewCellWithReuseIdentifier:CellIdentifier rowNumber:indexPath.row];
}
//tableView.backgroundColor = [UIColor clearColor];
return cell;
}
- (UITableViewCell *)tableviewCellWithReuseIdentifier:(NSString *)identifier rowNumber:(NSInteger)row
{
CGRect rect;
rect = CGRectMake(0.0, 0.0, 360.0, ROW_HEIGHT);
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:rect reuseIdentifier:identifier] autorelease];
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.00, 10.00, 150.00, 100.00)];
myImageView.tag = IMAGE_TAG;
[cell.contentView addSubview:myImageView];
[myImageView release];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(170.00, -10.00, 170.00, 80.00)];
label.tag = LABEL_TAG;
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor blackColor]];
[label setFont:[UIFont fontWithName:@"AmericanTypewriter" size:22]];
[label setTextAlignment:UITextAlignmentLeft];
[cell.contentView addSubview:label];
[label release];
if (row == 0)
{
UIImageView *imageView = (UIImageView *)[cell viewWithTag:IMAGE_TAG];
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"cover_v.jpg"]];
UILabel *mylabel = (UILabel *)[cell viewWithTag:LABEL_TAG];
mylabel.text = [NSString stringWithFormat:@"COVER PAGE"];
}
}