在表视图中改进滚动性能

时间:2011-11-22 12:12:47

标签: uitableview ios4

我正在使用自定义单元格的UItableview。自定义单元格的图像包含大量细节。但我的滚动是跳跃的。如何提高滚动性能?

我在这里发布我的代码:

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {       
        NSUInteger row = [indexPath row];



        Theo1AppDelegate *iDelegate = [[UIApplication sharedApplication] delegate];

        static NSString * ListitemCellIdentifier  = @"ListitemCellIdentifier";
        ListItemCell * cell  = (ListItemCell *)[tableView dequeueReusableCellWithIdentifier:ListitemCellIdentifier];

            if( cell == nil   )
            {
                [[NSBundle mainBundle] loadNibNamed:@"ListItemCell" owner:self options:nil];

                cell = self.mCell;
                self.mCell = nil;
             }



            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
            SampleObject * p = nil;
p = [self.mSelections objectAtIndex:row ];
            cell.tag = row;

            cell.mPropertyLabel.text = [p Address];
            NSString * comboStr1 = [NSString stringWithFormat:@"%d ",  (int)[p.mBeds doubleValue] ];

            cell.mBedBathSqftLabel.text = comboStr1;

            NSNumber * number = [NSNumber numberWithDouble:[p.mBaths doubleValue]];
            NSString * string = [number stringValue];

            int le = [string length];
            if(le == 1)
            {
                cell.mBathLabel.frame = CGRectMake(590, 60, 30, 23);
                cell.mBathLabel.text = string;
            }
            else if(le == 3)
            {
                cell.mBathLabel.frame = CGRectMake(590, 60, 35, 23);
                cell.mBathLabel.text = string;
            }
            else if(le == 4)
            {
                cell.mBathLabel.frame = CGRectMake(590, 60, 40, 23);
                cell.mBathLabel.text = string;
            }


            int sqftval = [p.mLivingArea intValue];

            NSString * sqft = @"";
            if(sqftval == 0)
            {

                cell.mSqftLabel.text =@"NA";
            }
            else 
            {
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
                NSString * isqft = [numberFormatter stringFromNumber:[NSNumber numberWithInt:sqftval] ];
                sqft = [NSString stringWithFormat:@"%@", isqft];
                cell.mSqftLabel.text = sqft;
                [numberFormatter release];
            }


            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
            [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
            NSString * pStr = [numberFormatter stringFromNumber:p.mPrice];
            NSString * pStr1 =[pStr substringToIndex:[pStr length]- 3 ];
            cell.mPriceLabel.text = pStr1;
            [numberFormatter release];



            NSString * cross = @"";
            if( p.mCrossStreet != nil )
                cross = [NSString stringWithFormat:@"%@", p.mCrossStreet];
            cell.mCrossStLabel.text = cross;
            if([p.mParkingTotal intValue] == 0)
            {
                cell.mParkingLabel.text = @"NA";
            }
            else 
            {
                NSString * parkingStr = [NSString stringWithFormat:@"%d", [p.mParkingTotal intValue] ];
                cell.mParkingLabel.text = parkingStr;
            }



            NSString * Notes = @"";
            if( p.mRemarks != nil )
                Notes = [NSString stringWithFormat:@"%@",  p.mRemarks];
                cell.c.editable = FALSE;

            int len = [Notes length];
            if ( len < 240)
            {
                 cell.mNotes.text = Notes;

            }
            else 
            {
                NSString * curString = [agentNotes substringToIndex:240];
                curString = [curString stringByAppendingString:@"...."];
                cell.mNotes.text= curString;
            }


                cell.selectionStyle = UITableViewCellSelectionStyleNone;

            cell.mID = p.mID;

            return cell;
        }

1 个答案:

答案 0 :(得分:1)

你可以把

cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
你的单元格中的

== nil if语句,所以每次都不会执行。我没有看到检查字符串长度以更改mBathLabel的帧的重点。并且你的2 NSNumberFormatter可以成为类的属性,因此它们不必每次都是alloc / init / release。