ios UITableView UILabel 内存泄露 内存泄露uitableviewuilabelios界面 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是自定义cell吗? 把实现部分的代码帖一下。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellWithIdentifier = @"Cell"; FYCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier]; NSLog(@"tableViewtableViewtableView--->%d", [indexPath row]); if (cell == nil) { cell = [[FYCellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellWithIdentifier]; cell.backgroundColor = [UIColor colorWithRed:236/255.0f green:232/255.0f blue:211/255.0f alpha:1.0]; cell.selectionStyle = UITableViewCellSelectionStyleNone; NSLog(@"cell == nil"); } else { NSLog(@"cell != nil"); } NSUInteger row = [indexPath row]; ObjectInfo valueInfo = CoreService::getSharedService()->app.getNearbyVC()[row]; NSString *name = [[NSString alloc] initWithCString:valueInfo.GetabyObjectName() encoding:NSUTF8StringEncoding]; cell.nameLabel.text = name; CGSize nameSize = [name sizeWithFont:cell.nameLabel.font]; cell.nameLabel.frame = CGRectMake(85, 12, nameSize.width, 15); int photoCounts = valueInfo.GetphotoCounts(); if( photoCounts > 0 ){ cell.albumImg.frame = CGRectMake(90+nameSize.width, 12, 15, 15); cell.albumImg.hidden = NO; }else{ cell.albumImg.hidden = YES; } FYUtil *util = [[FYUtil alloc] init]; NSString *skillStr = [[NSString alloc] initWithFormat:@"Lv.%@",[util displayLevel:valueInfo.Getprestige()]]; [cell.skillLabel setText:skillStr]; NSString *charmStr = [[NSString alloc] initWithFormat:@"魅力 %d",valueInfo.Getcharm()]; [cell.charmLabel setText:charmStr]; if( strlen(valueInfo.GetabySignature()) == 0 ){ [cell.signatureLabel setText:@"这个人还没写个性签名!"]; }else{ NSString *signature = [[NSString alloc] initWithCString:valueInfo.GetabySignature() encoding:NSUTF8StringEncoding]; [cell.signatureLabel setText:signature]; } int gender = valueInfo.GetGender(); if( gender == 0 ){ [cell.genderImg setImage:[UIImage imageNamed:@"GlobalMale"]]; }else if( gender == 1 ){ [cell.genderImg setImage:[UIImage imageNamed:@"GlobalFemale"]]; } NSString *distance = [[NSString alloc] initWithFormat:@"%.2fkm",valueInfo.GetDistance()]; cell.distanceLab.text = distance; cell.distanceLab.frame = CGRectMake(0, 16, 313, 10); cell.distanceLab.textAlignment = NSTextAlignmentRight; FYC__ToOC *convert = [[FYC__ToOC alloc] init]; NSString *temp = [[NSString alloc] initWithString:[convert convertFaceId:valueInfo.GetabyObjectFaceId()]]; [cell egoImageViewWithImg:temp]; return cell;} 通过你上面的代码,有需要优化的地方- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}这个代理方法会在cell创建时被调用,也就是说有多少数据就会被调用多少次。所以说在这个代理方法内最好是只是有绑定cell元素的操作,避免出现调用其它方法来获取数据等的数据操作,因为这些操作可能会很耗时,而且又被每次执行,cell渲染慢是可想而知。我的建议是在给uitableview的datasource中来处理。这样你只需要处理好一次datasource,在上面的代理方法中使用时就会快很多。 字符串直接[NSString stringWithFormat:...]不行吗,为什么还要[NSString alloc] ? 你要是没用arc模式,初始化的对象要release掉 使用beginAnimations的问题 可以取到手指在屏幕的覆盖范围吗? 安卓系统和ios系统接收邮件不兼容问题 请教如何修改cellForRowAtIndexPath方法,以返回不同的cell? IOS越狱与没有越狱的区别,APP怎么去识别。 为什么照书上写的 [XXX release]有编译错误? 请问怎么实现Forward、back 关于instrument的问题 PC蓝牙搜索不到苹果手机蓝牙(已开启),怎么破? 关于导航栏自带返回手势返回时遇到的问题 内存泄露 软键盘输入内容上涨 UITabBarController如何实现子页面跳转
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellWithIdentifier = @"Cell";
FYCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
NSLog(@"tableViewtableViewtableView--->%d", [indexPath row]);
if (cell == nil) {
cell = [[FYCellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellWithIdentifier];
cell.backgroundColor = [UIColor colorWithRed:236/255.0f green:232/255.0f blue:211/255.0f alpha:1.0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSLog(@"cell == nil");
}
else
{
NSLog(@"cell != nil");
}
NSUInteger row = [indexPath row];
ObjectInfo valueInfo = CoreService::getSharedService()->app.getNearbyVC()[row]; NSString *name = [[NSString alloc] initWithCString:valueInfo.GetabyObjectName() encoding:NSUTF8StringEncoding];
cell.nameLabel.text = name;
CGSize nameSize = [name sizeWithFont:cell.nameLabel.font];
cell.nameLabel.frame = CGRectMake(85, 12, nameSize.width, 15);
int photoCounts = valueInfo.GetphotoCounts();
if( photoCounts > 0 ){
cell.albumImg.frame = CGRectMake(90+nameSize.width, 12, 15, 15);
cell.albumImg.hidden = NO;
}else{
cell.albumImg.hidden = YES;
} FYUtil *util = [[FYUtil alloc] init];
NSString *skillStr = [[NSString alloc] initWithFormat:@"Lv.%@",[util displayLevel:valueInfo.Getprestige()]];
[cell.skillLabel setText:skillStr]; NSString *charmStr = [[NSString alloc] initWithFormat:@"魅力 %d",valueInfo.Getcharm()];
[cell.charmLabel setText:charmStr];
if( strlen(valueInfo.GetabySignature()) == 0 ){
[cell.signatureLabel setText:@"这个人还没写个性签名!"];
}else{
NSString *signature = [[NSString alloc] initWithCString:valueInfo.GetabySignature() encoding:NSUTF8StringEncoding];
[cell.signatureLabel setText:signature];
}
int gender = valueInfo.GetGender();
if( gender == 0 ){
[cell.genderImg setImage:[UIImage imageNamed:@"GlobalMale"]];
}else if( gender == 1 ){
[cell.genderImg setImage:[UIImage imageNamed:@"GlobalFemale"]];
} NSString *distance = [[NSString alloc] initWithFormat:@"%.2fkm",valueInfo.GetDistance()];
cell.distanceLab.text = distance;
cell.distanceLab.frame = CGRectMake(0, 16, 313, 10);
cell.distanceLab.textAlignment = NSTextAlignmentRight;
FYC__ToOC *convert = [[FYC__ToOC alloc] init];
NSString *temp = [[NSString alloc] initWithString:[convert convertFaceId:valueInfo.GetabyObjectFaceId()]];
[cell egoImageViewWithImg:temp];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}
这个代理方法会在cell创建时被调用,也就是说有多少数据就会被调用多少次。所以说在这个代理方法内最好是只是有绑定cell元素的操作,避免出现调用其它方法来获取数据等的数据操作,因为这些操作可能会很耗时,而且又被每次执行,cell渲染慢是可想而知。
我的建议是在给uitableview的datasource中来处理。这样你只需要处理好一次datasource,在上面的代理方法中使用时就会快很多。