I am trying to create a photo feed using a UITableView. I have the code to create the table and, when a photo is taken, display it in the feed but the image isn't displaying. The image is defiantly being captured and if I use a UIImageView to display it, it works, but when I try to add it to the table, it doesn't. I have also noticed that when I click on a row of the empty table, my didSelectRow action isn't working so I'm not sure if the problem is with the table or the way the image is being displayed.
Here is the code I am using to create the table:
tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
tableView.separatorColor = [UIColor clearColor];
[self.view addSubview:tableView];
[_tableView release];
[self.tableView release];
Here is the rest of the code for the table:
#pragma mark - UITableViewDataSource
// number of section(s), now I assume there is only 1 section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView
{
return 1;
}
// number of row in the section, I assume there is only 1 row
- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// if (indexPath.section >= self.objects.count) {
// // Load More Section
// return 320.0f;
// }
//
return 320.0f;
}
// the cell will be returned to the tableView
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"HistoryCell";
// Similar to UITableViewCell, but
PhotoCell *cell = (PhotoCell *)[theTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[PhotoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
// Just want to test, so I hardcode the data
cell.descriptionLabel.text = @"Testing";
cell.thumbImage = self.thumbImage;
//cell.backgroundView = self.thumbImage;
return cell;
}
#pragma mark - UITableViewDelegate
// when user tap the row, what action you want to perform
- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detailsViewController = [[DetailViewController alloc] init];
[self.navigationController pushViewController:detailsViewController animated:YES];
}
Here is the PhotoCell.M:
#import "PhotoCell.h"
#import "FeedViewController.h"
#import "DetailViewController.h"
@implementation PhotoCell
@synthesize thumbImage = _thumbImage;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// configure control(s)
UIImageView *testView = [[UIImageView alloc] initWithImage:self.thumbImage];
testView.frame = CGRectMake(0, 0, 320, 320);
[self addSubview:testView];
[self bringSubviewToFront:testView];
}
return self;
}
@end