好的,这里需要一些帮助.我是Swift的新手.这是我的问题.
在为我的UITableView获取数据时,我正在从URL中调用图像数据,因此在抓取重用的单元格时会有轻微的延迟,从而导致单元格显示旧数据半秒钟.我试图调用func prepareForReuse来重置属性,但它似乎没有工作.任何帮助表示赞赏!
这是调用单元格时的代码:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.alpha = 0
let book = books[indexPath.row]
cell.textLabel?.text = book.bookTitle
cell.detailTextLabel?.text = book.postURL
let url = URL(string: book.postPicture)
DispatchQueue.global().async {
let data = try? Data(contentsOf: url!)
DispatchQueue.main.async {
cell.alpha = 0
cell.backgroundView = UIImageView(image: UIImage(data: data!))
UIView.animate(withDuration: 0.5, animations: {
cell.alpha = 1
})
}
}
cell.contentView.backgroundColor = UIColor.clear
cell.textLabel?.backgroundColor = cell.contentView.backgroundColor;
cell.detailTextLabel?.backgroundColor = cell.contentView.backgroundColor;
func prepareForReuse(){
cell.alpha …
Run Code Online (Sandbox Code Playgroud) 所以使用组件看起来像这样:
<ParentListComponent Header="Test">
<ChildListItemComponent Name="1"/>
<ChildListItemComponent Name="2"/>
<ChildListItemComponent Name="3"/>
<ChildListItemComponent Name="4"/>
</ParentListComponent>
Run Code Online (Sandbox Code Playgroud)
而ParentListComponent
会是这个样子:
@foreach(var childComponent in listComponents){
@childComponent
}
@code{
[Parameter]
Public List<ChildListItemComponent> listComponents { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过将它作为 ChildContent 传递来轻松呈现它,如下所示,但我真的很想保留列表,以便我可以轻松地从父项访问每个项目。
[Parameter]
public RenderFragment ChildContent { get; set; }
Run Code Online (Sandbox Code Playgroud)
我觉得我只是缺少这里的语法,但不幸的是我找不到这方面的信息。如果您能提供帮助,我将不胜感激。