2

プログラムで多数のテーブルビューを作成しています。クライアントは、UITableView コントローラーではないレイアウトを具体的に要求しました。何かのようなもの:

ここに画像の説明を入力

テーブルビューの数と各テーブルの項目数は異なります。ビューが読み込まれると、すべてのテーブルが一度に作成されます。テーブル ビューのセルにサムネイルを追加したいと思います。サムネイルを遅延読み込みする方法を見つける必要があります。UITableViewController に遅延ロードを正常に実装しました。以前の成功の一部は、[tableview reloadData] 呼び出しを使用して、画像がキャッシュされた後にセルのサムネイルを表示できることを示すことができるためです。プログラムで作成されたテーブルビューに遅延読み込みを実装するにはどうすればよいですか? 私の最初のアイデアは、特定のセルの画像がキャッシュされたらセルを更新するために、テーブルビューにある種のセレクターを追加することです。これがどのように機能するかはわかりませんが、助けていただければ幸いです。

以下は、プログラムでテーブル ビューを作成するために使用するコードです (私は ARC を使用しています)。

@interface SyllabusSegmentedViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, weak)IBOutlet UIScrollView *SyllabusSegmentedSV;

--

@implementation SyllabusSegmentedViewController

- (void) viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];

   // Programmatic creation of the table views and titles for Table Views 
   [self ProgramaticCreationOfTableView:self];
}

-(void) ProgramaticCreationOfTableView:(id)sender {
    for (numTableViews = 0; numTableViews < [syllabusDispayed.LevelNames count]; numTableViews ++) {

    // Create Table View
    UITableView *newTableView = [[UITableView alloc] init];
    newTableView = [self createTableView:self];

    // Create UILabel that will act as Title for Each table view
    UILabel *newLabel = [[UILabel alloc] initWithFrame:[self MakeHeaderLabelFrame:numTableViews workingTableView:newTableView]];
    [newLabel setBackgroundColor:nil];
    newLabel.backgroundColor = [UIColor colorWithRed:(204/255.0) green:(204/255.0) blue:(204/255.0) alpha:1.0];
    newLabel.text = [syllabusDispayed.LevelNames objectAtIndex:numTableViews];
    newLabel.textAlignment = NSTextAlignmentCenter;
    UIFont *font = [UIFont boldSystemFontOfSize:20];
    UIColor *color = [UIColor darkGrayColor];
    newLabel.font = font;
    newLabel.textColor = color;


    [newTableView setBackgroundView:nil];
    newTableView.backgroundColor = [UIColor colorWithRed:(204/255.0) green:(204/255.0) blue:(204/255.0) alpha:1.0];
    newTableView.scrollEnabled = NO;

    newTableView.frame = ([self MakeTableViewFrame:numTableViews workingTableView:newTableView]);

    newTableView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    newLabel.autoresizingMask     = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

    [SyllabusSegmentedSV addSubview:newTableView];
    [SyllabusSegmentedSV addSubview:newLabel];
    }
  }

-(UITableView *)createTableView:(id)sender {
    UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.accessibilityLabel = [NSString stringWithFormat:@"%d", numTableViews];

    return tableView;
 }

-(CGRect)MakeHeaderLabelFrame:(int)workingTableNumber workingTableView:(UITableView *)newTableView {
    int numberOfPreviousLevelsRows = 0;

    for (int i = 0; i < workingTableNumber ; i ++) {
    numberOfPreviousLevelsRows += [[syllabusDispayed.SyllabusDictionary objectForKey:[syllabusDispayed.LevelNames objectAtIndex:i]] count];
    }

    return CGRectMake(0, 75 + ((workingTableNumber * 80) + (numberOfPreviousLevelsRows *55)), self.view.bounds.size.width, 25);
 }


-(CGRect)MakeTableViewFrame:(int)workingTableNumber workingTableView:(UITableView *)newTableView {
    int numberOfPreviousLevelsRows = 0;

     for (int i = 0; i < workingTableNumber ; i ++) {
     numberOfPreviousLevelsRows += [[syllabusDispayed.SyllabusDictionary objectForKey:[syllabusDispayed.LevelNames objectAtIndex:i]] count];
     }

    return CGRectMake(0, 95 + ((workingTableNumber * 80) + (numberOfPreviousLevelsRows *55)), self.view.bounds.size.width, 65*[newTableView numberOfRowsInSection:0]);
 }

また、次のような UITableViewDelegate に必要な関数も実装しました。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
4

1 に答える 1