bluetooth99 2013-05-30 02:12 采纳率: 0%
浏览 2331

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;
  • 写回答

4条回答

  • ReyZhang 移动开发领域新星创作者 2013-05-30 05:47
    关注

    你的问题出在设置uitableview的delegate,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];
    

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

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作