[英]UITableView doesn't show images
It appears my tableview delegate won't show my image at all. 看来我的tableview代表根本不会显示我的图像。 The image shows fine on my UIImageView that I added to my view controller.
该图像在添加到视图控制器的UIImageView上显示正常。 I am using the table view from interface builder if this bit of information helps.
如果这方面的信息有帮助,我正在使用界面构建器中的表视图。
- (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;
} }
You need to set the delegate and datasource in your viewDidLoad method and within your .h file in stead of the delegate method of the tableview itself. 您需要在viewDidLoad方法中以及.h文件中而不是tableview本身的委托方法中设置委托和数据源。
EDIT: 编辑:
Also make sure that all your delegates methods are added 还要确保添加了所有委托方法
Those delegates are: 这些代表是:
// 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
{
}
Try setting the delegate and data source via interface builder
, Or in the viewDidLoad
method. 尝试通过
interface builder
或在viewDidLoad
方法中设置委托和数据源。
-(void)viewDidLoad{
self.tableView.delegate = self;
self.tableView.dataSource = self;
//...
}
Also, make sure that the myImage
object is not nil
另外,请确保
myImage
对象不是nil
If i can remember correctly, default
style has an imageView property. 如果我没记错的话,
default
样式具有imageView属性。 Try: 尝试:
cell.imageView.image = [UIImage imageNamed:@"image.png"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.