Dee*_* ML 0 iphone uitableview
我想在表格视图单元格中添加收藏夹图像.我正在使用此代码
static NSString *CellIdentifier = @"memberCell";
MemberCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *item = self.searchList[indexPath.row];
cell.memberFullName.text = [item[@"full_name"] uppercaseString] ;
cell.memberPosition.text = [item[@"title"] length] < 1 ? [NSString stringWithFormat:@"%@", item[@"districts"]] : [NSString stringWithFormat:@"%@, %@", item[@"title"], item[@"districts"]];
cell.memberRoom.text = [NSString stringWithFormat:@"Rm %@", item[@"room_number"] ];
[cell.memberImage setImageWithURL:[NSURL URLWithString:item[@"image_thumb"]]
placeholderImage:[UIImage imageNamed:@"placeholder"]];
if(![item[@"fid"] isEqualToString:@"0"]) {
[cell.memberFavoriteImage setImage:[UIImage imageNamed:@"favorite"]];
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是最喜欢的图像显示在多个单元格上,即使条件if(![item[@"fid"] isEqualToString:@"0"]) 只传递给1个单元格,当我这样做时NSLog,条件只传递一次,但显示的图像是一个系统的顺序(即每个第9个行),当我一直向下滚动并返回时,顺序完全改变,图像显示在不同的行中.我不确定发生了什么,请帮忙.
出列指令可能返回现有的单元实例
试试这个
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:@"%d_%d",indexPath.section,indexPath.row];
MemberCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[MemberCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *item = self.searchList[indexPath.row];
cell.memberFullName.text = [item[@"full_name"] uppercaseString] ;
cell.memberPosition.text = [item[@"title"] length] < 1 ? [NSString stringWithFormat:@"%@", item[@"districts"]] : [NSString stringWithFormat:@"%@, %@", item[@"title"], item[@"districts"]];
cell.memberRoom.text = [NSString stringWithFormat:@"Rm %@", item[@"room_number"] ];
[cell.memberImage setImageWithURL:[NSURL URLWithString:item[@"image_thumb"]]placeholderImage:[UIImage imageNamed:@"placeholder"]];
if(![item[@"fid"] isEqualToString:@"0"]) {
[cell.memberFavoriteImage setImage:[UIImage imageNamed:@"favorite"]];
} else {
[cell.memberFavoriteImage setImage:nil];
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1410 次 |
| 最近记录: |