• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 以编程方式创建的表格 View 的延迟称重传感器图像

[复制链接]
菜鸟教程小白 发表于 2022-12-12 13:22:43 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在以编程方式创建许多表格 View 。客户特别要求一个不是 UITableView Controller 的布局。比如:

enter image description here

表格 View 的数量以及每个表格中的项目数量各不相同。加载 View 时会立即创建所有表。我想为表格 View 中的单元格添加缩略图。我需要找到一种延迟加载缩略图的方法。我已经成功地在 UITableViewController 上实现了延迟加载。我之前的成功部分是因为我可以使用 [tableview reloadData] 调用来指示可以在缓存图像后显示单元格缩略图。我如何对以编程方式创建的 TableView 实现延迟加载?我最初的想法是在表格 View 中添加某种选择器,以便在为特定单元格缓存图像后更新单元格。我不确定这将如何工作,并希望得到任何帮助。

以下是我用来以编程方式创建 TableView 的代码(我使用的是 ARC):

@interface SyllabusSegmentedViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

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

--

@implementation SyllabusSegmentedViewController

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

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

-(void) ProgramaticCreationOfTableViewid)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 colorWithRed204/255.0) green204/255.0) blue204/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 colorWithRed204/255.0) green204/255.0) blue204/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 *)createTableViewid)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)MakeHeaderLabelFrameint)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 



Best Answer-推荐答案


看看图书馆SDWebImage

我想这就是你要找的。

但可能是您的方法的真正问题:我想实际上没有必要创建一个接一个地定位的多个 TableView - 在这种情况下,部分可能会做这件事。

编辑

TableViewDataSource 有名为 -numberOfSectionsInTableView: 的方法。

也可以通过实现--tableView:heightForHeaderInSection:--tableView:heightForFooterInSection: 来获得section之间必要的空间。

您应该在 SyllabusSegmentedViewController 中实现所有这些方法。

关于ios - 以编程方式创建的表格 View 的延迟称重传感器图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18083866/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap