【发布时间】:2014-04-18 03:32:23
【问题描述】:
我有一个表格视图,我想为我的UITableviewCell 设置一个图像。我在 Storyboard 中为我的 imageView 设置了自动调整大小,但是当我在 Simulator 上运行它时,图像并没有按照我的意愿站在正确的位置。
我希望 Storyboard 中的这个支架是这样的:
但在模拟器中显示不同,如下所示:
这就是我在 TableViewCell 中设置图像的方式
@interface CBBookDetailCell : UITableViewCell
@property(weak,nonatomic) IBOutlet UIImageView *imageView;
-(void) setBookImage:(NSString*) imageLocal;
@end
@implementation CBBookDetailCell
-(void) setBookImage:(NSString*) imageLocal{
self.imageView.image = [UIImage imageWithContentsOfFile:imageLocal];
}
…
@end
我在 CellfromIndexPath 中调用它
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier;
if( indexPath.row == 0){
cellIdentifier = @"BookDetailCell";
CBBookDetailCell *cell ;
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
[cell setBookImage:imageLocal];
return cell;
} else{
cellIdentifier = @"ChapterCell";
CBChapterCell *cell;
CBChapter *chapter = [chapters objectAtIndex:indexPath.row-1];
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
[cell setChapterDetail:chapter.name PublishDate:chapter.publishDate];
return cell;
}
}
【问题讨论】:
-
能否包含以编程方式设置图像的代码?
-
我在上面编辑了我的问题。请看。谢谢
-
可以包含 cellforrowatindexpath() 吗?您的 VC 中是否还有其他地方可以与 self.imageView 进行交互?
-
我只是在 CBBookDetailCell.h 中设置了我的图像。在 cellforrowatindexpath() 中我只是调用了我的单元格。请查看我编辑的任务。
标签: ios uiimageview storyboard