【发布时间】:2015-01-09 15:08:05
【问题描述】:
我正在尝试像正常方式一样在 UITableViewCell 中显示名称和图像
cell.textLabel.text=@"some name";
cell.imageView.image=[array objectAtIndex:indexPath.row];
当我加载 ViewController 时,我可以看到所有图像都正确显示,但是当我尝试单击任何 UITableviewCell 时,图像大小变大(请查看示例截图)。
请帮我解决这个问题。
加载时间看起来像
当我点击第一个单元格时,单元格图像变大,如下图所示
请检查我的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.backgroundColor=[UIColor clearColor];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.backgroundColor=[UIColor clearColor];
if([userName count]>0){
cell.textLabel.text=[userName objectAtIndex:indexPath.row];
[cell.imageView setImageWithURL:[NSURL URLWithString:[[userList valueForKey:@"photo"] objectAtIndex:indexPath.row]]
placeholderImage:[UIImage imageNamed:@"avatar.png"]];
}
CGSize itemSize = CGSizeMake(40, 40);
UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[cell.imageView.image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.layer.masksToBounds=YES;
cell.imageView.layer.cornerRadius=9.0;
return cell;
}
我的 Didselect 方法是这样的
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *nib;
if ([[MyDevice getMyDevice] isiPad])
{
nib = @"nibname_iPad";
}
else
{
nib = @"nibname";
}
ViewController *chat = [[ViewController alloc] initWithNibName:xibName bundle:[NSBundle mainBundle]];
chat.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:chat animated:YES];
}
【问题讨论】:
-
我在这里回答了一个类似的问题:stackoverflow.com/a/40225516/2780252
标签: ios objective-c uitableview uiimage