我正在设置一个用sdwebimage下载的图像UITableViewCell.为了,为了保持UITableView从显示错误的图像,我需要将图像设置为nil在prepareForReuse.但是,我在实现这个方面遇到了一些麻烦.
这是我设置图像的地方:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * reuseIdentifier = @"programmaticCell";
MGSwipeTableCell * cell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (!cell) {
cell = [[MGSwipeTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
}
CGFloat brightness = [UIScreen mainScreen].brightness;
cell.textLabel.text = [self.streams[indexPath.row] name];
cell.detailTextLabel.text = [self.streams[indexPath.row] published];
NSString *imageUrl = [NSString stringWithFormat: @"%@", [self.streams[indexPath.row] photo]];
NSLog(@"Image is: %@ and path is: %d", imageUrl, indexPath.row);
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]
placeholderImage:[UIImage imageNamed:@"tile-blue.png"] options:indexPath.row == 0 ? SDWebImageRefreshCached : …Run Code Online (Sandbox Code Playgroud) 我是RxSwift的新手,我有以下代码来设置一个包含文本字段的tableview:
budget.expenses.asObservable()
.bindTo(tableView.rx.items(cellIdentifier: ExpenseInputCell.cellIdentifier, cellType: ExpenseInputCell.self)){(row, element, cell) in
cell.name.text = element.name.value
cell.name.rx.text
.bindTo(element.name)
.addDisposableTo(self.disposeBag)
}
.addDisposableTo(disposeBag)
tableView.rx.itemDeleted
.subscribe(onNext: {indexPath in
self.budget.expenses.value.remove(at: indexPath.row)
})
.addDisposableTo(disposeBag)
Run Code Online (Sandbox Code Playgroud)
一切工作正常,直到删除一行,因为然后混合了文本字段与数组中正确对象的绑定。例如,假设我在表视图中有7个项目,并且删除了第5行,新的第5和第6行的值都相同