我正在尝试使用 UITableView 创建照片流(比如 Instagram)。我有应该可以工作的代码,但图像仍未显示。如果我只是创建一个不属于表格的 UIImageView,则会显示图像,但是当我尝试将其添加到表格时,它不会出现。表格出现了,只是没有图像。这是代码 -
正在创建表的视图控制器
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// NSInteger sections = self.objects.count;
// if (self.paginationEnabled && sections != 0)
// sections++;
// return sections;
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PhotoCell";
PhotoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.thumbImage = [UIImage imageNamed:self.thumbImage];
if (cell==nil) {
cell = [[PhotoCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
return cell;
}
单元格视图控制器 -
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
UIImageView *imageView = [[UIImageView alloc] initWithImage:self.thumbImage];
imageView.frame = CGRectMake( 0.0f, 0.0f, 320.0f, 320.0f);
imageView.backgroundColor = [UIColor blackColor];
imageView.contentMode = UIViewContentModeScaleAspectFit;
self.photoButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.photoButton.frame = CGRectMake( 0.0f, 0.0f, 320.0f, 320.0f);
self.photoButton.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.photoButton];
NSLog(@"Working");
[self.contentView bringSubviewToFront:self.imageView];
}
return self; }
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state }
#pragma mark - UIView
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = CGRectMake( 20.0f, 0.0f, 280.0f, 280.0f);
self.photoButton.frame = CGRectMake( 20.0f, 0.0f, 280.0f, 280.0f); }
@end
我正在使用这个将一个视图中捕获的图像发送到另一个视图 -
PhotoCell *photoCell = [[PhotoCell alloc] init];
photoCell.thumbImage = self.thumbImage;