Я видел приложение под названием ZuluTrade, у которого есть диаграммы в ячейках tableView.
Похоже, это изображения в tableViewCell imageView.
Когда страница загружает tableView, сначала отображается текст, а затем загружаются изображения в tableViewCell при прокрутке tableView.
Это помогает повысить производительность, поскольку пользователю не нужно ждать, пока все элементы будут загружены в ячейку, а также обеспечивает плавную прокрутку tableView.
Как можно достичь этой функции?
Вот скриншоты приложения:
![enter image description here](https://i.stack.imgur.com/xR3xo.png)
![enter image description here](https://i.stack.imgur.com/nqNTu.png)
Код в моей таблице. cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier %i", indexPath.row];
MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
//if (cell == nil) {
cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
NSString *testVal = [[NSUserDefaults alloc] valueForKey:@"idValue"];
if (testVal == (NSString *)[NSNull null]) {
testVal = @"NULL";
}
//NSLog(@"testVal : %@",testVal);
NSLog(@"Fund Name : %@",[[array1 objectAtIndex:indexPath.row] valueForKey:@"FundName"]);
NSDate *date = [NSDate date];
NSDateFormatter *dtFormat = [[NSDateFormatter alloc] init];
[dtFormat setDateFormat:@"yyyy-MM-dd"];
NSString *dtString = [dtFormat stringFromDate:date];
NSString *fundname = [NSString stringWithFormat:@"%@",[[array1 objectAtIndex:indexPath.row] valueForKey:@"FundName"]];
NSString *imageName =[NSString stringWithFormat:@"%@_%@.png",fundname,dtString];
//NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [self getImagePath];
NSLog(@"Image Path : %@",documentsDirectory);
NSError *error1;
NSString *filepath1;
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error1];
if (files == nil) {
NSLog(@"Error reading contents of documents directory: %@", [error1 localizedDescription]);
}
NSLog(@"FileName: %@",imageName);
BOOL success = NO;
for (NSString *file in files)
{
NSLog(@"file in Files is %@",file);
if([file isEqualToString:[NSString stringWithFormat:@"%@",imageName]])
{
filepath1 = [documentsDirectory stringByAppendingPathComponent:file];
NSLog(@"Full Path :%@",filepath1);
success = YES;
}
}
if(success == YES)
{
cell.imageView.image = [UIImage imageWithContentsOfFile:filepath1];
}
else if(success != YES)
{
cell.imageView.image = [UIImage imageNamed:@"newfund.png"];
}
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(60.0, 0, 120.0,
tableView.rowHeight)] autorelease];
[cell addColumn:50];
label.textColor = [UIColor blackColor];
label.tag = LABEL_TAG;
label.font = [UIFont systemFontOfSize:12.0];
//NSLog(@"%@",[[array1 objectAtIndex:indexPath.row] valueForKey:@"FundName"]);
label.text = [NSString stringWithFormat:@"%@",[[array1 objectAtIndex:indexPath.row] valueForKey:@"FundName"]];
//NSLog(@"FundName: %@",label.text);
label.textAlignment = UITextAlignmentCenter;
//label.textColor = [UIColor blueColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label];
return cell;
}