gpt4 book ai didi

ios - 为什么我不能在表格 View 中显示我的图像?

转载 作者:行者123 更新时间:2023-11-29 02:57:08 24 4
gpt4 key购买 nike

cell.imageView.image=[UIImage imageNamed:@"yoman.png"];

我已经将图像添加到 images.xcassets为什么还是显示不出来。

最佳答案

确保您的代码中包含以下所有内容:-

没有。 1: 包含UITableViewDataSource,UITableViewDelegate

@interface TableViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation TableViewController

没有。 2: 将您的viewController 指定为tableView 的委托(delegate)和数据源

- (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 中,则在 Images.xcassets 中显示该图像应该没有问题strong>tableviewcell.

关于ios - 为什么我不能在表格 View 中显示我的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23749160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com