UICollectionView cell imageview not show image, but it's show background color xcode [duplicate] - objective-c

I have an issue with the images not showing, even though they are loading. I have tried this several different ways and the same result... no images. I do get white rectangles that are the size and color specified in the Storyboard. I get the correct number of rectangles in the popover. The log shows the names and ids correctly.
If I call the array directly, I get the same result... white rectangles.
My target is iOS7. Running Xcode 5.0.2. Images are coming from a SQL database. This is a live app, which I am updating to full iOS7 and where I am swapping out a custom grid layout for UICollectionView. Using a CollectionViewController, embedded into a NavigationController, which is accessed via a UIButton. As you can see, there is no custom cell. The images are to show in a popover and are then selectable by the user to change the background of the underlying view.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:#"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:#"fileName"];
NSLog(#"Filename: %#", tempImage);
NSLog(#"ButtonTagNumber: %#", buttonTagNumber);
UIImageView *image = [[UIImageView alloc]init];
image.image = [UIImage imageNamed:tempImage];
NSLog(#"Image.image: %#", image.image);
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
The fix which includes actually naming the BackgroundCell (duh) in the cellForItemAtIndexPath method and creating a small method in the BackgroundCell controller to set the image.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
BackgroundCell *cell = (BackgroundCell *)[collectionView dequeueReusableCellWithReuseIdentifier:#"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:#"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:#"fileName"];
[cell setImage:[UIImage imageNamed:tempImage]];
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
The main cell code;
- (id)initWithFrame:(CGRect)frame
{
_backgroundImage = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
[self.contentView addSubview:_backgroundImage];
if (self) {
// Initialization code
}
return self;
}
-(void)setImage:(UIImage *)image
{
_backgroundImage.image = image;
}

The problem is that the image is not being set in the cell's view hierarchy. To do that, subclass UICollectionViewCell and create a imageView property in the subclass:
#interface CollectionViewCellSubclass : UICollectionViewCell
#property (nonatomic, strong) UIImageView *imageView;
#end
...and init the UIImageView in its initWithFrame:
_imageView = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
[self.contentView addSubview:_imageView];
Set this subclass as the Custom Class for the cell in storyboard and then load it in the collectionView:cellForItemAtIndexPath method above setting the image to the cell's image subview:
CollectionViewCellSubclass *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"BckgndCell" forIndexPath:indexPath];
//...
cell.imageView.image = [UIImage imageNamed:tempImage];
Hope this helps.

Adding cell.contentView.frame = [cell bounds] after the line dequeueReusableCellWithReuseIdentifier worked for me.
Suppose you add a custom (200,200) UICollectionViewCell through xib and change its frame somewhere in the code to be e.g. (120,120). You have to set its content view’s frame accordingly, otherwise image on its imageView (which is on its content view) will not be shown properly.

Related

UICollectionView images not showing

I have an issue with the images not showing, even though they are loading. I have tried this several different ways and the same result... no images. I do get white rectangles that are the size and color specified in the Storyboard. I get the correct number of rectangles in the popover. The log shows the names and ids correctly.
If I call the array directly, I get the same result... white rectangles.
My target is iOS7. Running Xcode 5.0.2. Images are coming from a SQL database. This is a live app, which I am updating to full iOS7 and where I am swapping out a custom grid layout for UICollectionView. Using a CollectionViewController, embedded into a NavigationController, which is accessed via a UIButton. As you can see, there is no custom cell. The images are to show in a popover and are then selectable by the user to change the background of the underlying view.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:#"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:#"fileName"];
NSLog(#"Filename: %#", tempImage);
NSLog(#"ButtonTagNumber: %#", buttonTagNumber);
UIImageView *image = [[UIImageView alloc]init];
image.image = [UIImage imageNamed:tempImage];
NSLog(#"Image.image: %#", image.image);
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
The fix which includes actually naming the BackgroundCell (duh) in the cellForItemAtIndexPath method and creating a small method in the BackgroundCell controller to set the image.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
BackgroundCell *cell = (BackgroundCell *)[collectionView dequeueReusableCellWithReuseIdentifier:#"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:#"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:#"fileName"];
[cell setImage:[UIImage imageNamed:tempImage]];
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
The main cell code;
- (id)initWithFrame:(CGRect)frame
{
_backgroundImage = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
[self.contentView addSubview:_backgroundImage];
if (self) {
// Initialization code
}
return self;
}
-(void)setImage:(UIImage *)image
{
_backgroundImage.image = image;
}
The problem is that the image is not being set in the cell's view hierarchy. To do that, subclass UICollectionViewCell and create a imageView property in the subclass:
#interface CollectionViewCellSubclass : UICollectionViewCell
#property (nonatomic, strong) UIImageView *imageView;
#end
...and init the UIImageView in its initWithFrame:
_imageView = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
[self.contentView addSubview:_imageView];
Set this subclass as the Custom Class for the cell in storyboard and then load it in the collectionView:cellForItemAtIndexPath method above setting the image to the cell's image subview:
CollectionViewCellSubclass *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"BckgndCell" forIndexPath:indexPath];
//...
cell.imageView.image = [UIImage imageNamed:tempImage];
Hope this helps.
Adding cell.contentView.frame = [cell bounds] after the line dequeueReusableCellWithReuseIdentifier worked for me.
Suppose you add a custom (200,200) UICollectionViewCell through xib and change its frame somewhere in the code to be e.g. (120,120). You have to set its content view’s frame accordingly, otherwise image on its imageView (which is on its content view) will not be shown properly.

UIImageView in UICollectionViewCell in UITableViewCell bug

The settings for the UICollectionView were defined using IB (ie scroll direction: horizontal, etc), and was embedded in UITableViewCell using IB.
UICollectionViewCell displays, images display, however, images are stacked on top of one another, instead of one image per one cell with fidelity.
I made individual UIImageView for each picture as instance variables, and same occurred using if and switch statements in the cellForItemAtIndexPath message.
Since IB was used, it may be a stretch to identify the bug, however, would you please help to identify the bug in case it is obvious from the code? Thanks.
#implementation AccountTableViewCell
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
imageArray = #[[UIImage imageNamed:#"image1.png"], [UIImage imageNamed:#"image2.png"], [UIImage imageNamed:#"image3.png"], [UIImage imageNamed:#"image4.png"], [UIImage imageNamed:#"image5.png"]];
self.oCollectionView.dataSource = self;
[self.oCollectionView setFrame:self.contentView.frame];
[self.contentView addSubview:self.oCollectionView];
self.oCollectionView.backgroundColor = [UIColor clearColor];
[self.oCollectionView reloadData];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return imageArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"accountCell" forIndexPath:indexPath];
UIImageView* iv = [[UIImageView alloc] init];
[cell.contentView addSubview:iv];
[iv setFrame:cell.contentView.frame];
iv.image = imageArray[indexPath.row];
return cell;
}
#end
It's because you keep on adding an UIImageView to the cell each time it's dequeued.
Instead, you should subclass the UICollectionViewCell (let's call it "MYCollectionViewCell", add a UIImageView to the cell subclass in the storyboard and set the UIImageView as an outlet on the subclass.
Then, within cellForItemAtIndexPath, set that imageView's image like so:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"accountCell" forIndexPath:indexPath];
cell.imageView.image = imageArray[indexPath.row];
return cell;
}

UITableView content of cell dont move on editing

I have a UITableView with some custom cells. In each cell, there is a ImageView and three labels and get the data from a string array. I have done the layout in my storyboard. The data source is a string array. This works.
Now I have insert a EditButton in the code. Now i can see the EditButton, but when I activate the edit mode the table cell will be resized, but the images and labels dont move.
Can you show me how to move the content of the cell? Who knows a tutorial with UITableView uses EditMode AND storyboards. All tutorials which I have found are based on the "old" Xcode.
Thank you very much
By the way, here is my code:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
myData = [NSMutableArray arrayWithObjects:
#"Line1_Label1|Line1_Label2|Line1_Label3",
#"Line2_Label1|Line2_Label2|Line2_Label3",
#"Line3_Label1|Line3_Label2|Line3_Label3",
nil];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myData count];
}
// Return a cell for the table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// A cell identifier which matches our identifier in IB
static NSString *CellIdentifier = #"CellIdentifier";
// Create or reuse a cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Get the cell label using its tag and set it
NSString *currentItem = [myData objectAtIndex:indexPath.row];
NSArray *itemArray = [currentItem componentsSeparatedByString:#"|"];
UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
[cellLabel setText:itemArray[0]];
UILabel *cellLabel2 = (UILabel *)[cell viewWithTag:3];
[cellLabel2 setText:itemArray[1]];
UILabel *cellLabel3 = (UILabel *)[cell viewWithTag:4];
[cellLabel3 setText:itemArray[2]];
// get the cell imageview using its tag and set it
UIImageView *cellImage = (UIImageView *)[cell viewWithTag:2];
[cellImage setImage:[UIImage imageNamed: #"control.png"]];
return cell;
}
// Do some customisation of our new view when a table item has been selected
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:#"ShowSelectedMovie"]) {
// Get reference to the destination view controller
ItemViewController *vc = [segue destinationViewController];
// get the selected index
NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
// Pass the name and index of our film
[vc setSelectedItem:[NSString stringWithFormat:#"%#", [myData objectAtIndex:selectedIndex]]];
[vc setSelectedIndex:selectedIndex];
}
}
#end
First of all, make an IBOutlet of the tableview in the .h and synthesize it in the .m.
Then make an action to the edit button (if you don't already have one). In the action, write:
CGRect rect = yourTableView.cell.contentView.frame;
//Do whatever changes you wish to do with the sizing of the view. origin changes placement and size changes size (duh). Line below is an example.
rect.origin.y = yourTableView.cell.contentView.frame.origin.y - 20;
yourTableView.cell.contentView.frame = rect;
This won't be animated, but I think it'll fulfill your purpose.
Overwrite the -(void)layoutSubviews{} - method of your custom UITableViewCellController.m or if you don't use a custom UITableViewCellController, try it in your UITableViewController. But I haven't tried it yet with no custom UITableViewCellController.
Something like this will do the trick:
-(void) layoutSubviews {
[super layoutSubviews];
CGFloat xPositionOfElementInTableCell = 273.0f; /* the position of the element before going into edit mode */
if (self.isEditing && !self.showingDeleteConfirmation) // if we enter editing mode but not tapped on the red minus at the moment
{
xPositionOfElementInTableCell = 241.0f;
} else if (self.isEditing && self.showingDeleteConfirmation) // after we tappet on the red minus
xPositionOfElement = 193.0f;
}
CGRect frameOfElementInTableCell = self.myElementInTableCell.frame;
frameOfElementInTableCell.origin.x = xPositionofElement;
self.myElementInTableCell.frame = frameOfElementInTableCell;
}
I hope it helps you. The idea for this code is not mine. I found it here in SO, too. Don't know where exactly.

UICollectionView with FlowLayout not scrolling when setting section insets

I am using a UICollectionView programmatically.
I've set its frame as follows:
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 3000) collectionViewLayout:flowLayout];
My UICollectionViewFlowLayout has a section inset set as:
flowLayout.sectionInset = UIEdgeInsetsMake(20.0, 20.0, 100.0, 20.0);
I also only have 1 section.
I've set the height to be 3,000 to see if the collection view would scroll but it doesn't. I am setting it to that since the collection view doesn't seem to scroll up or down when I insert new items.
UICollectionView is subclassed from a UIScrollView, which means I can keep resetting the scroll view content size. Would this work properly?
The only issue is that this would work if I know the sizes of all items including how many items are on each row.
If each item had a different size, how would I find out the size of each row? I would need that to add all row sizes and increase the content size height of self.collectionView.
EDIT
Even my suggestion above, resetting the content size, does not work properly! I tried the following when updating my collection view:
int numberOfRows = self.dataArray.count / 3;
self.collectionView.contentSize = CGSizeMake(self.view.frame.size.width, (numberOfRows * 200) + 300);
This is very ugly though. This is because it assumes all my images are of size 200x200px, which fits 3 images per row (hence the division by 3).
Furthermore, even with the +300 that I have, the last row I can only see about 3/4 of it and not all of it. I have to scroll more and I will be able to see it but it goes back up again to 3/4. Its kind of like the scroll to refresh, where the view only moves if you drag it and when you leave it bumps back to where it was. Why is this happening? Is it just that Apple designed UICollectionView so poorly? This is a little ridiculous... UITableViews adjust their scroll according to their content automatically.
In answering some of your other questions about UICollectionView, I created this demo project, and it scrolls just fine, so I don't know what problem you're having. The only thing I needed to do to make the last row wholly visible was to increase the size of the bottom inset to 90. I also added a completion method to the performBatchUpdates:completion: to automatically scroll so that the last added item is visible (notice that I add some extra items by using performSelector;withObject:afterDelay:). My images are 48x48, and I just set my collection view to the bounds of my controller's view. Here is the code so you can compare it to what you have:
#interface ViewController () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout> {
NSMutableArray *newData;
}
#property (nonatomic, retain) UICollectionView *collectionView;
#property (nonatomic, retain) NSMutableArray *results;
#end
#implementation ViewController
- (void)viewDidLoad {
self.results = [NSMutableArray array];
int i = 11;
while (i<91) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:#"New_PICT00%d.jpg",i]];
[self.results addObject:image];
i++;
}
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
//flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
self.view.backgroundColor = [UIColor blackColor];
[self.view addSubview:self.collectionView];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"Cell"];
//[self.collectionView registerClass:[RDCell class] forCellWithReuseIdentifier:#"myCell"];
[self.collectionView reloadData];
[self performSelector:#selector(addNewImages:) withObject:nil afterDelay:3];
}
-(void)addNewImages:(id)sender {
newData = [NSMutableArray array];
int i = 102;
while (i<111) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:#"New_PICT0%d.jpg",i]];
[newData addObject:image];
i++;
}
[self addNewCells];
}
-(void)addNewCells {
NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
[self.collectionView performBatchUpdates:^{
int resultsSize = [self.results count];
[self.results addObjectsFromArray:newData];
for (int i = resultsSize; i < resultsSize + newData.count; i++)
[arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
[self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths];
}
completion: ^(BOOL finished){
[self.collectionView scrollToItemAtIndexPath:arrayWithIndexPaths.lastObject atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:YES];
}];
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return [self.results count];
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
//cell.iv.image = [self.results objectAtIndex:indexPath.row];
cell.backgroundColor = [UIColor colorWithPatternImage:[self.results objectAtIndex:indexPath.row]];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
UIImage *image = [self.results objectAtIndex:indexPath.row];
return CGSizeMake(image.size.width, image.size.height);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(10, 10, 90, 10);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"Selected Image is Item %d",indexPath.row);
}
Setting the height of the UICollectionView to 3000 will make your scrolling problem worse. If the UICollectionView is 3000 pixels tall then it will only ever need to scroll if it has more than 3000 pixels worth of content in it. You should set it to the height of the view it is contained in (same as the width).
AFAIK the also should not set the contentSize directly, instead you need to override the - (CGSize)collectionViewContentSize method in a subclass of UICollectionViewLayout, but generally speaking you shouldn't need to change the content size for normal uses.
I'm not totally clear on what your problem is - is it that when you add more than a screens worth of items you can't scroll?
I've encountered the same problem because I was initializing the elements of my collectionView (i.e. it's DataSource) in the viewWillAppear method.
I finally add just a [self.collectionView reloadData]; and it works just fine!
Maybe you're in the same case.

Sizing a Custom UITableViewCell and included UIImageView based on Image Size

I am trying to customize the UITableViewCell below for an iPhone app in a grouped table view. What I would like to do is have the image width take up the whole cell minus padding (280) and the height variable based on the image size.
Currently I am using SDWebImage to asynchronously download remote images. This may not be the correct thing to do in this case. I am also having trouble figuring out how to give the custom cell the image on initialization. The image URL is stored in self.beerPhoto in the DetailViewController.
I have searched for this a number of ways and have not found exactly what I am looking for. The closest was this: How to scale a UIImageView proportionally, but this method seems to require the cell to have the image at initialization, as I tried to make this code work but setting the image after initialization left a blank cell.
The current code includes constants I set to approximate an image in portrait orientation. In reality some of the images are portrait and some are landscape orientation.
Please let me know if there's anything additional you need to know.
Header for custom UITableViewCell:
#import <UIKit/UIKit.h>
#interface BeerDetailHead : UITableViewCell {
UILabel *beerName;
UIImageView *beerImage;
}
#property(nonatomic, retain)UILabel *beerName;
#property(nonatomic, retain)UIImageView *beerImage;
#end
Relevant portion of implementation for custom UITableViewCell
#import "BeerDetailHead.h"
#implementation BeerDetailHead
#synthesize beerName, beerImage;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
//beerName = [[UILabel alloc]init];
//beerName.textAlignment = UITextAlignmentLeft;
//beerName.font = [UIFont systemFontOfSize:14];
beerImage = [[UIImageView alloc]init];
//[self.contentView addSubview:beerName];
[self.contentView addSubview:beerImage];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+10 ,10, 280, 375);
beerImage.frame = frame;
}
DetailViewController's cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
NSArray *listData =[self.tableContents objectForKey:
[self.sortedKeys objectAtIndex:[indexPath section]]];
NSLog(#"listData = %#", listData);
NSUInteger row = [indexPath row];
if ([self.sortedKeys objectAtIndex:[indexPath section]] == #"header"){
static NSString *headerTableIdentifier = #"HeaderTableIdentifier";
BeerDetailHead * headerCell = (BeerDetailHead*)[tableView
dequeueReusableCellWithIdentifier: headerTableIdentifier];
if(headerCell == nil) {
headerCell = [[[BeerDetailHead alloc] initWithFrame:CGRectZero reuseIdentifier:headerTableIdentifier] autorelease];
}
headerCell.beerName.text = [listData objectAtIndex:row];
[headerCell.beerImage setImageWithURL:[NSURL URLWithString:self.beerPhoto]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
//NSLog(#"frame = %#", headerCell.beerImage.frame);
return headerCell;
}
else{
//use standard UITableViewCell
}
}
Implement tableView:heightForRowAtIndexPath: delegate method and return calculated height for each row from this method.
After loading each image call reloadData on your tableView OR if you want to animate changes call:
[self.tableView beginUpdates];
[self.tableView endUpdates];
Also, you might want to combine several sequence height updates into one. I would use I little delay to perform this:
// triggerUpdates calls the above code
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(triggerUpdates) object:nil];
[self performSelector:#selector(triggerUpdates) withObject:nil afterDelay:0.1];