繁体   English   中英

UITableView不显示图像

[英]UITableView doesn't show images

看来我的tableview代表根本不会显示我的图像。 该图像在添加到视图控制器的UIImageView上显示正常。 如果这方面的信息有帮助,我正在使用界面构建器中的表视图。

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


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

cell.accessoryView = [[UIImageView alloc] initWithImage:myimage];

return cell;

}

您需要在viewDidLoad方法中以及.h文件中而不是tableview本身的委托方法中设置委托和数据源。

编辑:

还要确保添加了所有委托方法

这些代表是:

// Return the number of sections
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

// Return the number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

//filling of tableview
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

}

//pressing of a row
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

尝试通过interface builder或在viewDidLoad方法中设置委托和数据源。

-(void)viewDidLoad{
self.tableView.delegate = self;
self.tableView.dataSource = self;
//...
}

另外,请确保myImage对象不是nil

如果我没记错的话, default样式具有imageView属性。 尝试:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM