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 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型