0

我正在尝试在一些原型单元格中添加 UIImages。我认为出了问题的是我似乎无法在不需要的地方摆脱 UIImage 视图。

4

3 回答 3

0

你可以试试这个:

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

   // Your code..

return cell;

}

删除条件if (cell == nil)

希望这能解决你的问题。

一切顺利 !!!

于 2013-03-11T05:58:12.830 回答
0

您需要使用 UIImageView 为您的图像制作一个自定义单元格,将其加载到您的 tableView 中,然后将您的图像加载到此 UIImageView 中。要创建自定义单元格,您需要创建新类“新文件 - 目标 c 类 - UITableViewCell 的子类”和新的空 Xib。然后,您需要向您的 xib 添加一个单元格。

在此处输入图像描述

不要忘记显示这个单元格的类

在此处输入图像描述

我创建了名为“Cell”的类,这就是为什么我可以在 cell.h 中的菜单中看到单元格类,添加所有你需要的。例如 UIImageView。

#import <UIKit/UIKit.h>

@interface Cell : UITableViewCell {
}

@property (nonatomic, strong) IBOutlet UIImageView *myView;

@end

西布

在此处输入图像描述

(我创建了名为“Cell”的类,这就是为什么我可以在我的菜单中看到单元格类)

现在您可以将图像添加到班级中的单元格(tableview 在哪里)

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

Cell *myCell = (Cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (myCell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CountCell"owner:self options:nil];
    myCell = [nib objectAtIndex:0];
   }
myCell.myImage = [UIImage imageNamed:@"image.png"];

return myCell;
}

希望这会有用。对不起我的英语不好 )

于 2013-03-11T06:15:32.737 回答
0

每次滚动表格视图时,都会刷新行索引的单元格。如果您可以发布您的cellForRowIndex方法,我们可以指出错误(如果有)。我的猜测是在您的cellForRowIndex方法中,您正在清除某处的文本和图像,并且由于某些条件而没有向它们填充值。这必须是评论,但遗憾的是我没有特权

于 2013-03-11T06:38:33.523 回答