我正在以编程方式创建许多表格 View 。客户特别要求一个不是 UITableView Controller 的布局。比如:
表格 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
看看图书馆SDWebImage
我想这就是你要找的。p>
但可能是您的方法的真正问题:我想实际上没有必要创建一个接一个地定位的多个 TableView - 在这种情况下,部分可能会做这件事。
编辑
TableViewDataSource 有名为 -numberOfSectionsInTableView:
的方法。
也可以通过实现--tableView:heightForHeaderInSection:
或--tableView:heightForFooterInSection:
来获得section之间必要的空间。
您应该在 SyllabusSegmentedViewController 中实现所有这些方法。
关于ios - 以编程方式创建的表格 View 的延迟称重传感器图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18083866/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) | Powered by Discuz! X3.4 |