2013-05-29 53 views
1

看来我的tableview委托不会显示我的图像。该图像显示在我的视图控制器添加到我的UIImageView罚款。如果这一点信息有帮助,我正在使用接口构建器的表视图。UITableView不显示图像

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

}

回答

1

尝试通过interface builder设置委托和数据源,或者在viewDidLoad方法。

-(void)viewDidLoad{ 
self.tableView.delegate = self; 
self.tableView.dataSource = self; 
//... 
} 

此外,还要确保myImage对象不是nil

,如果我能记错的话,default风格有一个ImageView的属性。尝试:

cell.imageView.image = [UIImage imageNamed:@"image.png"]; 
+0

我尝试这样做,但我得到这个错误。 - [ViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例0x81ec820 –

+1

确保您正在调用'numberOfRowsInSection:'方法。并返回您在阵列中拥有的对象数量。 – LAMBORGHINI

+0

'cell.imageView.image = [UIImage imageNamed:@“image.png”];'是做到这一点的正确方法 –

1

您需要设置委托和数据源在您的viewDidLoad方法,并在实现代码如下本身的委托方法代替你的.h文件中。

编辑:

另外,还要确保你所有的委托方法添加

这些代表是:

// Return the number of sections 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

// Return the number of rows 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 5; 
} 

//filling of tableview 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

} 

//pressing of a row 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

} 
+0

我尝试这样做,但我得到这个错误 - [视图控制器的tableView:numberOfRowsInSection:]:无法识别的选择发送到实例0x81ec820 –