Thursday, December 26, 2013

The rookie questions about uitableviewcell

cellForRowAtIndexPath delegate method to add and set up a uilabel
/ / Display dateTime
NSString * groupTitle = [keys objectAtIndex: section];
if ([groupTitle isEqualToString: @ "earlier"]) {
UILabel * dateLabel = [[UILabel alloc] initWithFrame: CGRectMake (tableView.bounds.size.width-130, cell.detailTextLabel.frame.origin.y, 130, cell.detailTextLabel.frame.size.height)];
dateLabel.tag = 2000;
/ / Only do the interception date display, temporarily displayed.

NSString * dateText = [pItem getAttribValue: @ "datetime"];
if ([dateText length] == 17) {
dateText = [dateText substringToIndex: 8];
}
else if ([dateText length] == 18) {
dateText = [dateText substringToIndex: 9];
}
else
{
dateText = [dateText substringToIndex: 10];
}


dateLabel.text = dateText;
dateLabel.textAlignment = UITextAlignmentLeft;
dateLabel.backgroundColor = [UIColor clearColor];
dateLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;

[Cell.contentView addSubview: dateLabel];
[DateLabel release];
}

Time can be displayed in a normal first page, if the page or screen slide up and down uilabel in time to refresh the display is not correct, I do not know why, ask the experts.
Thank you.

Reply:
[MyTableView reloadData];
Reply:
Content to be updated regularly on the upstairs methods.
Reply:
This is caused because the cell reuse, and data refresh nothing before addsubview, first remove the label
contentview
Reuse is the table in order to save memory, if the use of the memory cell has not only created once one into an interface will appear, Aspect code to know more, you can not repeat this time add lebel, saw themselves
Reply:
reference to the third floor arthurchenjs reply:
This is caused because the cell reuse, and data refresh nothing before addsubview, first remove contentview the label < br />
Reuse is the table in order to save memory, if the use of the memory cell has not only created once one into an interface will appear, Aspect code to know more, you can not repeat this time add lebel, saw himself < / blockquote>

Trouble ask uilabel to how clear? Thank you.
Reply:
You do not have tag = 2000 yet
viewWithTag can take to label
Then label calls removeFromSuperView

Investigate cell reuse issues now

For example: You can display a screen 5 cell, but you have a total of six cell, because the system will reuse mechanism alloc 5 δΈͺ cell, when you scroll the screen to show the sixth cell, the system will not help you re- In alloc a cell, but the use of the first cell, is due to rolling

Was removed from the cell to re-screen as the "six" a cell. However, due to the first cell has not been release out, so there's view is preserved, is your textfield, label, image and the like are still there, so the display will repeat it again.

Solutions can have each a new cell, so that the most direct and easy to understand, he is not reused, every alloc.

Or you call [cell.contentview addSubview:] in the subview before contentview all empty.

UITableViewCell * cell = [_filterTableView dequeueReusableCellWithIdentifier: startDateCellIdentifier];

if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: startDateCellIdentifier] autorelease];
}
else
{
for (uiview * view in cell.contentView.subviews)
[View removeFromSuperview]; This is traversing all clear, can figure
}

No comments:

Post a Comment