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
首先,你这个写法貌似有问题,我不清楚你的界面生成器指的是什么,但是
把delegate和datasource设置在创建tableView的地方,你这个位置都写的有问题