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!