The below code works fine when i am not adding any extra row all the content view are controlled(hide/visible) but problem when adding to dummy rows.
i am having a table view created programatically.i am initializing my cell with some content view(labels & buttons).I am adding two dummy rows as : if indexPath.row > [mYarray count].I am trying to hide my buttons in extra added rows.BUt when i’m scrolling the buttons are some times hiding from cell or some time displaying in cell.The condition is something like: if(indexPath.row < [mYarray count]) then buttons MAY(See below code,the condition which decides to hide/visible if(ShowNQButton)) be hide/visible.But if(indexPath.row > [mYarray count]) then buttons MUST be hide/invisible/removed.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:Identifier] autorelease];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
waitTimeLabel=[[[UILabel alloc] initWithFrame:CGRectMake(210, 0, 50, 30)]autorelease];
waitTimeLabel.backgroundColor=[UIColor clearColor];
waitTimeLabel.tag=lblTAG5;
waitTimeLabel.numberOfLines=2;
waitTimeLabel.font=[UIFont systemFontOfSize:13];
[cell.contentView addSubview:waitTimeLabel];
EstSeatLabel=[[[UILabel alloc] initWithFrame:CGRectMake(270, 0, 60, 30)]autorelease];
EstSeatLabel.backgroundColor=[UIColor clearColor];
EstSeatLabel.tag=lblTAG6;
EstSeatLabel.font=[UIFont systemFontOfSize:12];
[cell.contentView addSubview:EstSeatLabel];
}
else
{
waitTimeLabel=(UILabel *)[cell viewWithTag:lblTAG5];
EstSeatLabel=(UILabel *)[cell viewWithTag:lblTAG6];
}
if (indexPath.row < [UIAppDelegate.waitlistDetailArray count]) {
NQbutton = [[UIButton alloc]init];
NQbutton.frame=CGRectMake(220, 4, 42, 24);
NQbutton.adjustsImageWhenHighlighted=NO;
NQbutton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
NQbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
UIImage *NQbuttonimage = [UIImage imageNamed:@"NqN"];
[NQbutton setBackgroundImage:NQbuttonimage forState:UIControlStateNormal];
[NQbutton addTarget:self action:@selector(NQbutton:event:) forControlEvents:UIControlEventTouchUpInside];
NQbutton.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:NQbutton];
[NQbutton release];
NQbuttonEstTime= [[UIButton alloc]init];
NQbuttonEstTime.frame=CGRectMake(275, 4, 42, 24);
NQbuttonEstTime.adjustsImageWhenHighlighted=NO;
NQbuttonEstTime.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
NQbuttonEstTime.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
UIImage *NQbuttonesttimeimage = [UIImage imageNamed:@"NqN"];
[NQbuttonEstTime setBackgroundImage:NQbuttonesttimeimage forState:UIControlStateNormal];
[NQbuttonEstTime addTarget:self action:@selector(NQbutton:event:) forControlEvents:UIControlEventTouchUpInside];
NQbuttonEstTime.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:NQbuttonEstTime];
[NQbuttonEstTime release];
if(ShowNQButton)//**this BOOL variable is outside of cellForRow decides if buttons //should be visible or not when indexPath.row < myArray' count.**
{
NQbutton.hidden=NO;
NQbuttonEstTime.hidden=NO;
}
else {
NQbutton.hidden=YES;
NQbuttonEstTime.hidden=YES;
}
}
else
{//i have added three dummy rows in numberOfRowsInSection(when indexpath.row > [myArray Count])
waitTimeLabel.text=@" ";
EstSeatLabel.text=@" ";
//below i am stuffing in removing/hiding these two contentViews from dummy cells
NQbutton.hidden=YES;//tried setImage=nil fornormalState//tried removeFromSupViw
NQbuttonEstTime.hidden=YES;//tried setImage=nil fornormalState//tried removeFromSupViw
}
}
return cell;
}
Any suggestions?
thanks
The problem is with the dequeue cell. If you look your code, you are adding the two buttons only on the
indexPath.row<[array cont]Logically its correct.So try with solution provided here