iphone - 如何在 UITableView 单元格上添加图像?

标签 iphone ios objective-c uitableview uiimageview

如何在 UITableView 的多个单元格中添加一张图片

我将一张图片添加到一个顶部单元格,如下所示:

screenshot

但是滚动到底部和顶部后我看到了这个:

screenshot

第二个和第三个单元格的 z-index 比第一个单元格大。

我该怎么做?

谢谢..

最佳答案

UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
imgView.image=[UIImage imageNamed:@"img.png"];
[cell addSubview:imv];

你也不能直接将图像添加到单元格

 -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{    
   static NSString* CellIdentifier = @"Cell";

   UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil)
      cell = [[[UITableViewCell alloc] UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

   cell.textLabel.text = @"I'm a UITableViewCell!";
   cell.imageView.image = [UIImage imageNamed:@"image.png"];

   return cell;
}

试试这段代码....

并调整图片大小....

关于iphone - 如何在 UITableView 单元格上添加图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18312969/

相关文章:

iphone - 将 NSString 转换为货币——完整的故事

android - 将相机 View 集成到我在 PhoneGap 中的应用程序中

iphone - 如何在 iOS 中更改键盘背景颜色?

objective-c - 如何创建一个c数组?

objective-c - 在一种情况下未调用 kAudioSessionProperty_AudioRouteChange 的回调

iPhone 基于导航的应用程序 - 一些全局工具栏问题

iOS:在字符串中查找url并将字符串更改为可点击(可点击)

ios - 推送 segue 后从导航堆栈中删除 View Controller (使用 Storyboard segues)

ios - 无法更改不同状态的 UIbutton 图像

ios - 如何在 iOS 上扩展 Activator 以识别新的输入手势?