Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

tableview cell text are overlapping while scrolling

I have UItableview where every cell is showing some data in 3 UILabel..all of these three label are in a UIView and UIView is the contentview of the cell.Now when i run the project at first table cell's are displaying fine but when i start scroll the tableview then cell text starts overlapping each other. please help me what is the solution of the problem.i have got a lot of similar question but these are no appropriate for my code so anybody please help me...this my code...




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @\"MyIdentifier\";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
cell.textLabel.font = [UIFont fontWithName:@\"Helvetica\" size:15.0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;

cellimage =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 275, 30)];
[cell.contentView addSubview:cellimage];

CGRect attributeNameRect = CGRectMake(0, 0, 138, 29);
attributeName = [[UILabel alloc] initWithFrame:attributeNameRect];
attributeName.textAlignment = UITextAlignmentCenter;
attributeName.textColor = [UIColor blackColor];
attributeName.font = [UIFont systemFontOfSize:12];
attributeName.backgroundColor = [UIColor clearColor];
attributeName.layer.borderColor = [UIColor grayColor].CGColor;
attributeName.layer.borderWidth = 1.0;
attributeName.tag = 1;
// [attributeName release];

CGRect nameValueRect = CGRectMake(138, 0, 57, 29);
nameValue = [[UILabel alloc] initWithFrame:nameValueRect];
nameValue.textAlignment = UITextAlignmentCenter;
nameValue.textColor = [UIColor blackColor];
nameValue.font = [UIFont systemFontOfSize:12];
nameValue.backgroundColor = [UIColor clearColor];
nameValue.layer.borderColor = [UIColor grayColor].CGColor;
nameValue.layer.borderWidth = 1.0;
nameValue.tag = 2;
// [nameValue release];

CGRect PercentageRect = CGRectMake(195, 0, 80, 29);
visitorPercentage = [[UILabel alloc] initWithFrame:PercentageRect];
visitorPercentage.textAlignment = UITextAlignmentCenter;
visitorPercentage.textColor = [UIColor blackColor];
visitorPercentage.font = [UIFont systemFontOfSize:12];
visitorPercentage.backgroundColor = [UIColor clearColor];
visitorPercentage.layer.borderColor = [UIColor grayColor].CGColor;
visitorPercentage.layer.borderWidth = 1.0;
visitorPercentage.tag = 3;
// [visitorPercentage release];
}





switch (indexPath.row) {
case 0:
{
attributeName.text = @\"visitor:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:0]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 1:
{
attributeName.text = @\"uniqueVisitor:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:1]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 2:
{
attributeName.text = @\"order:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:2]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 3:
{
attributeName.text = @\"revenue:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:3]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 4:
{
attributeName.text = @\"conversionRate:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:4]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 5:
{
attributeName.text = @\"newProduct:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:5]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 6:
{
attributeName.text = @\"outOfStockProduct:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:6]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 7:
{
attributeName.text = @\"productInCart:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:7]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 8:
{
attributeName.text = @\"visitorInc:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:8]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 9:
{
attributeName.text = @\"uniqueVisitorInc:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:9]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 10:
{
attributeName.text = @\"orderInc:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:10]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 11:
{
attributeName.text = @\"revenueInc:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:11]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 12:
{
attributeName.text = @\"ConvertionRateInc:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:11]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 13:
{
attributeName.text = @\"newProductInc:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:11]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 14:
{
attributeName.text = @\"outOfStockProductInc:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:11]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
case 15:
{
attributeName.text = @\"productInCartInc:\";
[cellimage addSubview:attributeName];

nameValue.text = [NSString stringWithFormat:@\"%@\",[[records objectAtIndex:0] objectAtIndex:11]];
[cellimage addSubview:nameValue];

visitorPercentage.text = @\"25%\";
[cellimage addSubview:visitorPercentage];
break;
}
default:
break;
}


return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return 30;
}
Post edited by Emon on

Replies

  • DomeleDomele Posts: 2,948Registered Users
    Because, UITableViews reuse cells. Every time a row comes into view, it calls cellForRowAtIndexPath. Every time this happens, you are adding a label to "cellimage".

    Add all your cellimage subviews and tag them inside the cell == nil. Then get references to them outside your cell == nil by calling viewWithTag on cellimage.

    Also, where did you define cellimage and all your other subviews?

    And one more thing, please use code tags from now, [CODE] [1/CODE] without the 1.
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.



    New app - See screenshots and details at www.globaclock.com.



    If you want to
  • EmonEmon Posts: 3New Users
    [QUOTE=Domele;383754]Because, UITableViews reuse cells. Every time a row comes into view, it calls cellForRowAtIndexPath. Every time this happens, you are adding a label to \"cellimage\".

    Add all your cellimage subviews and tag them inside the cell == nil. Then get references to them outside your cell == nil by calling viewWithTag on cellimage.

    Also, where did you define cellimage and all your other subviews?

    And one more thing, please use code tags from now, [CODE] [1/CODE] without the 1.[/QUOTE]


    thanks brother...it works now
Sign In or Register to comment.