Улучшение производительности прокрутки в табличном представлении - PullRequest
2 голосов
/ 22 ноября 2011

У меня 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 Ответ

1 голос
/ 09 января 2012

Вы могли бы поставить

cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

в вашей ячейке == nil if оператор, поэтому он не выполняется каждый раз. Я не вижу смысла проверять длину строки, чтобы изменить кадр mBathLabel. И ваши 2 NSNumberFormatter могут быть сделаны свойствами класса, поэтому их не нужно каждый раз размещать / инициализировать / освобождать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...