0
cell.imageView.image=[UIImage imageNamed:@"yoman.png"];
我已经将images添加到images.xcassets 为什么我仍然无法显示。为什么我不能在表格视图中显示我的图像?
cell.imageView.image=[UIImage imageNamed:@"yoman.png"];
我已经将images添加到images.xcassets 为什么我仍然无法显示。为什么我不能在表格视图中显示我的图像?
请确保您有以下所有在你的代码: -
1:包含UITableViewDataSource,的UITableViewDelegate
@interface TableViewController()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
@implementation TableViewController
2号:指定你的viewController作为代表和数据源的表查看
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate=self;
self.tableView.dataSource=self;
}
第3号:的行数您的tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
第4号:示例代码的cellForRowAtIndexPath
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString * reuseIdentifier = nil ;
UITableViewCell* cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"%d",indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"yoman"];
return cell;
}
如果你有上述所有,并与图像名称“yoman”在您的Images.xcassets中,您应该在显示图像时没有问题e在tableviewcell。
您是否收到任何错误? – Chris
不!它顺利运行 –
确保图像名称正确无误,并且区分大小写。你也可以做NSLog(@“%@”,cell.imageView.image);并看看它是否不为零,以确保您正确设置图像。 – Yan