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;

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

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

设置断点到这个方法(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
这个方法应该没有运行

你应该这xib文件中连接tableview的 delegate和datasource到file owner

首先,你这个写法貌似有问题,我不清楚你的界面生成器指的是什么,但是

  • (UITableViewCell )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 这个方法作为tableView的代理方法,必须有代理才能执行,但是你却把*声明代理写在代理方法里面,谁来执行这个代理方法**,你打一下断点,看程序会执行进来吗? 必须在创建这个tableView的时候就设置代理,也就是把下面这个两个方法写在tableView的初始化方法里面 [tableView setDelegate:self]; [tableView setDataSource:self];

把delegate和datasource设置在创建tableView的地方,你这个位置都写的有问题