解决方案 »

  1.   

    是自定义cell吗? 把实现部分的代码帖一下。
      

  2.   


    - (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;
    }
      

  3.   

    通过你上面的代码,有需要优化的地方
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}
    这个代理方法会在cell创建时被调用,也就是说有多少数据就会被调用多少次。所以说在这个代理方法内最好是只是有绑定cell元素的操作,避免出现调用其它方法来获取数据等的数据操作,因为这些操作可能会很耗时,而且又被每次执行,cell渲染慢是可想而知。
    我的建议是在给uitableview的datasource中来处理。这样你只需要处理好一次datasource,在上面的代理方法中使用时就会快很多。
      

  4.   

    字符串直接[NSString stringWithFormat:...]不行吗,为什么还要[NSString alloc] ?
      

  5.   

    你要是没用arc模式,初始化的对象要release掉