Custom UITableViewCell doesn't appear in the table
I have created a UITableViewCell and I am trying to display it in one of my table, but for some reason it doesn't come, the table is coming empty. And when I click on the one of cell in the table it takes me down to next level, which means the custom UITableViewCell is not getting rendered properly.
Here is my custom UITableViewCell .h file
@interface ProductViewCell : UITableViewCell {
IBOutlet UILabel *titleLabel;
IBOutlet UILabel *detailLabel;
IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *detailLabel;
@property (nonatomic, retain) UIImageView *imageView;
Here is the .m file
#import "ProductViewCell.h"
@implementation ProductViewCell
@synthesize titleLabel, detailLabel, imageView;
- (void)setSelected:(BOOL)selected animated:(BOOL)an开发者_开发问答imated {
[super setSelected:selected animated:animated];
}
@end
Here is the .h file which subclasses UITableViewController
@interface ProductCategoryViewController : UITableViewController {
NSArray *tableDataSource;
}
@property (nonatomic, retain) NSArray *tableDataSource;
Here is the .m file for ProductCategoryViewController
@implementation ProductCategoryViewController
@synthesize tableDataSource;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
ProductViewCell *cell = (ProductViewCell*)[tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[ProductViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
cell.titleLabel.text = [dictionary objectForKey:@"name"];
cell.imageView.image = [UIImage imageNamed:[dictionary objectForKey:@"imageUrl"]];
return cell;
}
Your help is appreciated.
Thanks, Yogesh
I got this working by making some changes, in my tableviewcontroller I added an IBOutlet for ProductViewCell and synthesis the same.
Then I changed the xib file for ProductViewCell 1) I make File's Owner to my tableViewController 2) Then here I linked the the IBOutlet that I created in the tableViewContoller to the ProductViewCell.
I am not sure if this is the right way to do it but atleast this is working for me now
精彩评论