抱歉,这是一个新问题,但我搜索了一整天仍然找不到答案。当我运行该应用程序时,它仅显示带有标签和计数的行,但图像未显示在表格 View 单元格上。
#import "ViewController.h"
@interface ViewController () <UITableViewDataSource, UITableViewDelegate> {
NSMutableArray * imageNameArray;
//__weak IBOutlet UIImageView *cell;
__weak IBOutlet UITableView *Table;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self arraySetup];
}
-(void) arraySetup {
imageNameArray = [NSMutableArray arrayWithArray[@"2.jpg"]];
}
- (NSInteger)tableViewUITableView *)tableView numberOfRowsInSection: (NSInteger)section {
return imageNameArray.count;
}
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath{
static NSString *cellId = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
//cell.imageView.image = [UIImage imageNamed:imageNameArray [indexPath.row]];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.textLabel.text = imageNameArray [indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat"%d", (int) indexPath.row + 1];
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(10,5, 50, 25)];
imv.image=[UIImage imageNamed"2.jpg"];
[cell.contentView addSubview:imv];
cell.imageView.image = imv.image;
return cell;
}
Best Answer-推荐答案 strong>
这里有一些非常基本的代码供您学习:
我正在使用基本类 UITableViewCell
-(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier"cell"];
cell.textLabel.text = @"Your table row text";
cell.imageView.image = [UIImage imageNamed"image.png"];// Here you specify your image
cell.detailTextLabel.text = @"Your descriptive text";
return cell;
}
关于ios - 如何将图像添加到uitableviewcell,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/45317095/
|