Welcome, Guest
Username Password: Remember me

Loading a Custom Cell From .xib
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Loading a Custom Cell From .xib

Loading a Custom Cell From .xib 1 year, 9 months ago #1

Can you advise me or send me sample code on how to load a custom bound cell from a .xib please?

I am using this code for a ImagePickerCell.xib in my ImagePickerCell.m

 
#import "ImagePickerCell.h"
 
 
@implementation ImagePickerCell
 
@synthesize myImageLabel;
@synthesize myImageView;
 
 
/*
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
// Initialization code
}
return self;
}*/

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
}
return self;
}
 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
 
[super setSelected:selected animated:animated];
 
// Configure the view for the selected state
}
 
 
- (void)dealloc {
 
[myImageView release];
myImageView = nil;
 
[myImageLabel release];
myImageLabel = nil;
 
[super dealloc];
}
 
 
@end
 


In my table I have this code...

 
if( indexPath.row == 0)
{
static NSString *CellIdentifier = @"ImagePickerCell";
cell = nil;
ImagePickerCell *cell = (ImagePickerCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
 
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ImagePickerCell" owner:self options:nil];
 
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (ImagePickerCell *) currentObject;
break;
}
}
}
UIImage *loadedImage = [UIImage imageNamed:@"noImage.png"];
cell.myImageLabel.text = @"TEST Image name";
cell.myImageView.image = loadedImage;
 
 
}else{
Shoe *thisObject = [[mainDelegate shoes] objectAtIndex:indexPath.row];
 
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.text = thisObject.myName;
cell.detailTextLabel.text = thisObject.designer;
NSString *imageName = thisObject.thumbName;
UIImage *loadedImage = [UIImage imageWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:[@"Documents/" stringByAppendingString:imageName]]];
cell.imageView.image = loadedImage;
}
 



Thanks so much!
  • baberuth22
  • OFFLINE
  • Expert Boarder
  • Posts: 84
  • Karma: 2

Re: Loading a Custom Cell From .xib 1 year, 9 months ago #2

Hi Bryan-

This is actually one of our feature requests and will be provided in a future release (estimated time duration: 3 weeks). For now, you have two alternatives:

1- Configure the cell view programmatically in the willConfigureCell delegate method. Here you can create everything you've created in the xib file programmatically.

2- Create the view (not the cell) in Interface Builder, then use the willConfigureCell delegate method to load the view and it to the cell as a subview.

We'll also keep you updated on the future release.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Loading a Custom Cell From .xib 1 year, 8 months ago #3

hey tarek,

could you provide an example for your 1.)

that would help me, too


thx
  • magegu
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Karma: 1

Re: Loading a Custom Cell From .xib 1 year, 8 months ago #4

Sure Just tell me what you're doing in the .xib file and I'll give you an example on how to achieve it using willConfigureCell.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Loading a Custom Cell From .xib 1 year, 8 months ago #5

ehm, just an easy example would be cool

a UIView with a UIImage and at the bottom of the Image there should be a UILabel ... nothing facy


thanks
  • magegu
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Karma: 1

Re: Loading a Custom Cell From .xib 1 year, 8 months ago #6

Here you go Martin-

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
willConfigureCell:(SCTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect imageFrame = CGRectMake(5, 0, 100, 100);
CGRect labelFrame = CGRectMake(5, imageFrame.size.height+5, imageFrame.size.width, 20);
 
cell.height = imageFrame.size.height + labelFrame.size.height + 10;
 
// Create the subviews
UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageFrame];
imageView.image = [UIImage imageNamed:@"task.png"];
[cell.contentView addSubview:imageView];
[imageView release];
UILabel *labelView = [[UILabel alloc] initWithFrame:labelFrame];
labelView.text = @"Task Label";
[cell.contentView addSubview:labelView];
[labelView release];
}
 
 
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
  • Page:
  • 1
  • 2
Time to create page: 1.12 seconds