[英]Can't view an image in table cell
伙計們
我正在做本教程,但是編寫代碼后,我在表格單元格中看不到任何圖像->它們是白色的!
我在“支持文件”文件夾中添加了圖片文件,又讀了一次教程,但不能解決此問題! 拜托,有人可以幫我嗎?
@interface CarTableViewController ()
@end
@implementation CarTableViewController
@synthesize carMakes = _carMakes;
@synthesize carImages = _carImages;
@synthesize carModels = _carModels;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.carMakes = [[NSArray alloc] initWithObjects:@"Chevy", @"BMW", @"Toyota", @"Volvo", @"Smart", nil];
self.carModels = [[NSArray alloc] initWithObjects:@"Volt", @"Mini", @"Venza", @"S60", @"Fortwo", nil];
self.carImages = [[NSArray alloc] initWithObjects:@"chevy_volt.jpg", @"mini_clubman.jpg", @"toyota_venza.jpg", @"volvo_s60.jpg", @"smart_fortwo.jpg", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.carModels count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"carTableCell";
CarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CarTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.makeLabel.text = [self.carMakes objectAtIndex:[indexPath row]];
cell.modelLabel.text = [self.carModels objectAtIndex:[indexPath row]];
UIImage *carPhoto = [UIImage imageNamed:[self.carImages objectAtIndex: [indexPath row]]];
cell.carImage.image = carPhoto;
return cell;
}
嘗試這個 ::
UIImage *im = [UIImage imageNamed:[NSString stringWithFormat:@"%@", self.carImages objectAtIndex: [indexPath row]]];
cell.imgCar.image = im;
如果仍然無法正常工作,則說明圖像未正確復制到項目中。 請刪除並再次添加。
並且不要偽造@synthesize您的imageView
謝謝,快樂編碼..
嘗試在Xib中設置方面適合的內容或通過以下代碼
cell.imgCar.image.imageViewContentmode = UIViewContentModeAspectFit;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.