我有一个UITableView
包含所有单元格的图像,但所有图像都已经在单元格上(我没有设置我自己的图像)并且它们都是从项目中包含的图像加载的。这些不是从服务器或任何东西加载的图像。但是,tableview 的滚动仍然有些生涩。有什么办法可以加快速度吗?我有在这里生成单元格的功能:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Post init, update with the fair info so it can attend/de-attend on its own
CompaniesCustomCell *cell = [CompaniesCustomCell dequeOrCreateInTable:tableView];
SectionInfo *sectionInfo = [sectionInfoArray objectAtIndex:indexPath.section];
cell.fairDictionary = [sectionInfo.arrMDetails objectAtIndex:indexPath.row];
[cell updateEventIcon:(NSString*)[[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"TYPE"]];
cell.lblFairName.text = [[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"TITLE"];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
// Set event start time, end time, and date
NSString *newDate = [MyUtil convertToLocalTime:@"MMMM dd, yyyy" :[[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"START_TIME"]];
NSString *startString = [MyUtil convertToLocalTime:@"hh:mm a" :[[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"START_TIME"]];
NSString *endString = [MyUtil convertToLocalTime:@"hh:mm a" :[[sectionInfo.arrMDetails objectAtIndex:indexPath.row] valueForKey:@"END_TIME"]];
cell.lblFairDate.text = newDate;
cell.lblFairStartTime.text = startString;
cell.lblFairEndTime.text = endString;
return cell;
}
有什么我做错了可能会减慢它的速度吗?
编辑
我在convertToLocalTime
这里包含了函数的代码,因为我认为这可能是根本原因。但是......我真的很困惑如何优化它。我正在从服务器获取时间戳值(以 UTC 为单位),并将其转换为用户本地时区。这个过程真的那么慢吗?
// Converts given time string into the users current timezone
// based on the location of their phone
+(NSString *)convertToLocalTime:(NSString*)format :(NSString*)stringDate {
// Get the date in the servers time zone
NSDate *date = [MyUtil convertToServerDate:stringDate];
// Convert the date to the local timezone
NSDateFormatter *localFormat = [[NSDateFormatter alloc] init];
[localFormat setDateFormat:format];
NSString *localDate = [localFormat stringFromDate:date];
[localFormat release];
return localDate;
}
// Provides a NSDate object with the servers timezone set
+(NSDate *)convertToServerDate:(NSString*)stringDate {
// First get the NSDate object in the servers timezone
NSTimeZone *tz = [NSTimeZone timeZoneWithName:ServerTimezone];
NSDateFormatter *inFormat = [[NSDateFormatter alloc] init];
[inFormat setDateFormat:@"yyyyMMddHHmmss"];
[inFormat setTimeZone:tz];
NSDate *date = [inFormat dateFromString:stringDate];
[inFormat release];
return date;
}