The scrolling is slow in the tableview (Obj-c)

Hi,

I have a tableview with an array of objects. If, the array of objects is for example 50 objects, when I scroll the tableview, the scroll is fast; but if, the array of objects are 500, scrolling is slow.
Why? Can I optimize it somehow?

In objects in the array, each object has various information.

This is the code of tableview:
#pragma mark - UITableViewDataSource & delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return [_array count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return 125.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self tableView:tableView discussionCellForAtIndexPath:indexPath];
}

-(UITableViewCell *)tableView:(UITableView *)tableView discussionCellForAtIndexPath:(NSIndexPath *)indexPath
{

Auto *obj = (Auto *)[_array objectAtIndex:indexPath.row];
static NSString *cellIdentifier = @“AutoCell";
AutoCell *cellAuto = (AutoCell *)[self.tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

if ([obj.cover length] == 0 || ([obj.cover isEqualToString:@""])){
    cellAuto.imgAuto.image = [UIImage imageNamed:avatarDefault];
    [cellAuto.imgAuto setContentMode:UIViewContentModeScaleAspectFit];
}else{
    dispatch_async (dispatch_get_main_queue(), ^{
        placeholderIMG=[UIImage imageNamed:avatarDefault];
        NSString *stringImg = [NSString stringWithFormat:@"%s/%@/%@",baseurlImgAuto, obj.idAuto, obj.cover];
        [cellAuto.imgAuto setImageWithURL:[NSURL URLWithString:stringImg] placeholderImage:placeholderIMG];
        [cellAuto.imgAuto setContentMode:UIViewContentModeScaleAspectFill];
    });
}

cellAuto.lblNameAuto.text = obj.name;

NSString *stringAddress = [NSString stringWithFormat:@"%@", obj.street];
if (stringAddress == (id)[NSNull null] || stringAddress.length == 0 || stringAddress == nil || [stringAddress isEqualToString:@"(null)"]){
    stringAddress = @"";
}
NSString *stringCity = [NSString stringWithFormat:@"%@", obj.city];
if (stringCity == (id)[NSNull null] || stringCity.length == 0 || stringCity == nil || [stringCity isEqualToString:@"(null)"]){
    stringCity = @"";
}
NSString *stringRegion = [NSString stringWithFormat:@"%@", obj.region];
if (stringRegion == (id)[NSNull null] || stringRegion.length == 0 || stringRegion == nil || [stringRegion isEqualToString:@"(null)"]){
    stringRegion = @"";
}
NSString *stringZipCode = [NSString stringWithFormat:@"%@", obj.zipCode];
if (stringZipCode == (id)[NSNull null] || stringZipCode.length == 0 || stringZipCode == nil || [stringZipCode isEqualToString:@"(null)"]){
    stringZipCode = @"";
}
cellAuto.lblAddress.text = [NSString stringWithFormat:@"%@ - %@, %@ %@",stringAddress,stringCity,stringRegion,stringZipCode];

if ([[UIDevice currentDevice] systemVersion].floatValue >= 9.0) {
    if ([self isForceTouchAvailable]) {
        self.previewingContext = [self registerForPreviewingWithDelegate:self sourceView:self.tableView];
    }
}

return cellAuto;

}

Thanks! :wink:

Some help for my problem?

@jack7 Thanks very much for your question! I would suggest that you utilize the UITableView’s prefetching method that Apple has introduced in iOS 10:

https://developer.apple.com/documentation/uikit/uitableviewdatasourceprefetching

What I would also recommend is to look at some tutorials online on how to use this method, and if you’re still stuck, I would advise you to perhaps post your question on:

www.stackoverflow.com and I can almost guarantee you that you’ll get an answer within 24 hours.

I hope this helps!

All the best!

And for iOS 9.0 or next (before iOS 10 and other), I can use it “uitableviewdatasourceprefetching”???

This is for iOS 10. Are you working on an older version?

Yes. iOS 9.x.x. The project started with iOS 9.0. Then?

@jack7 Hmmmmm. I did some digging for you, and I think the following question on
StackOverflow should provide you with a solid framework to solve your problem :slight_smile:

I hope this helps!

All the best!

This topic was automatically closed after 166 days. New replies are no longer allowed.