cellForRowAtIndexPath委托方法中添加并设置了一个uilabel
//Display dateTime
NSString *groupTitle = [keys objectAtIndex:section];
if ([groupTitle isEqualToString:@"更早"]) {
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;
//只截取日期做显示,暂时不显示时间。
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];
}时间可以在第一页中正常的显示,若翻页或屏幕上下滑动uilabel中时间刷新显示不正确,不知道为什么,请教高手。
谢谢。
//Display dateTime
NSString *groupTitle = [keys objectAtIndex:section];
if ([groupTitle isEqualToString:@"更早"]) {
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;
//只截取日期做显示,暂时不显示时间。
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];
}时间可以在第一页中正常的显示,若翻页或屏幕上下滑动uilabel中时间刷新显示不正确,不知道为什么,请教高手。
谢谢。
解决方案 »
- 一起读代码CryptoExercise
- 希望iphone版火起来
- html文件解析
- Xcode怎么在对象库里找到滚动条啊?
- 请教一下使用html5开发ios应用一般有什么入门书籍可以学习
- 用 Myeclipse完成了jquery mobile的代码,想把代码放到ios平台上应该怎么做?
- 【求助】请问UITextView 如何使显示不全的单词不折行显示
- 那么问题来了,你敢点开这吗?
- cocoapods启动失败:rror: RPC failed; curl 56 SSLRead() return error -9845
- IOS 界面传值
- ios UIWebView 中文解码问题
- 在网上看到这句代码,不知道什么意思
viewWithTag可以取到label
然后label调用removeFromSuperView调查一下cell重用的问题吧例如: 你一个屏幕可以显示5个cell,但你有6个cell总共,因为重用机制系统只会alloc 5个cell, 当你滚动屏幕来显示第六个cell的时候,系统并不会帮你重新在alloc一个cell,而是使用第一个cell,就是由于滚动被移出屏幕外的那个cell来重新作为第“六”个cell。但是由于第一个cell并没有被release掉,所以里面的view还是会保留下来,就是你的textfield,label,image之类的东西都还在,所以又会重复显示一遍。解决方法可以有,每次新建一个cell,这样最直接易懂,就是不用他的重用,每次alloc。或者在你调用 [cell.contentview addSubview:] 之前将contentview 里的subview全部清空。 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];这是遍历全清,自己看着办
}