开发者社区> 问答> 正文

关于UItableview 没有显示预期图片

tableview delegate不显示图片。在UIImageView 中显示就正常。tableView来自界面生成器

- (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;

展开
收起
爵霸 2016-03-19 14:24:19 1835 0
1 条回答
写回答
取消 提交回答
  • 你的问题出在设置uitableviewdelegate,datasource的时机不对.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    如上方法为uitableview的协议方法,需在先指定datasource的情况下才会被调用. 正确的做法是

    -(void)viewDidLoad {
            //在uitableivew load数据前,指明uitableview的delegate,datasource
           self.tableView.delegate=self;
           self.tableView.dataSource=self;
    }

    把在协议方法中的

    [tableView setDelegate:self];
    [tableView setDataSource:self];

    删除,再试.应该就可以了.

    2019-07-17 19:08:11
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载