UITableview cell value over writing again and again problem?
my tableview show like this when i scroll .......will u help what mistake i have done? any help please?if you see that image , the value i have selected in over writing........
http://www.freeimagehosting.net/image.php?fa76ce6c3b.jpg
the code is
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
CGRect rectLbl2 = CGRectMake(75 ,1, 215, 32);
CGRect rectLbl3 = CGRectMake(75 ,28, 215, 30);
addLabel2= [[UILabel alloc] initWithFrame:rectLbl2];
addLabel3= [[UILabel alloc] initWithFrame:rectLbl3];
addLabel2.text = @"senthil";
[cell addSubview:addLabel2];
[addLabel2 release]; // for memory release
addLabel3.text= @"senthil";
[cell addS开发者_运维百科ubview:addLabel3];
[addLabel3 release];
return cell;
}
Dequeueed cells already have a label so you are adding another label to these cells. Add the label in the initial UITableViewCell creation and just change the label contents.
Try something like this:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel *lab;
CGRect rectLbl2 = CGRectMake(75 ,1, 215, 32);
lab = [[UILabel alloc] initWithFrame:rectLbl2];
lab.tag = 2;
[cell addSubview:lab];
[lab release];
CGRect rectLbl3 = CGRectMake(75 ,28, 215, 30);
lab = [[UILabel alloc] initWithFrame:rectLbl3];
lab.tag = 3;
[cell addSubview:lab];
[lab release];
}
((UILabel *)[cell viewWithTag:2]).text = @"senthil";
((UILabel *)[cell viewWithTag:3]).text = @"senthil";
return cell;
}
The problem in my opinion is that you are re-allocating a new label each time the tableview scrolls and that is causing it to be re-wrote to the cell.
Also make sure you are using dequeueReusableCellWithIdentifier
properly. It may be the case that you are not dequeuing it properly.
Thats all i can say without looking at your code.
精彩评论