I've got a problem trying to create a custom tableview cell for my iPhone app in Xcode 4. I've created the .h and .m files, created IBOutlets for all of the subviews that should be present inside the cell, and dragged the actual controls onto the cell's XIB file in Interface Builder. However, I can't figure out how to connect the outlets to the IB controls. Every tutorial I read says to control-drag from the TableViewCell object in the objects list to the subviews, but when I do that my IBOutlets are not listed in the popup window. The only outlets that are available are 'acccessoryView', 'backgroundView', 'editingAccessoryView' and 'backgroundSelectedView'. Shouldn't I also be seeing my own IBOutlets in that list as well? Or am I not following the correct procedure? (I'm pretty new to iPhone development).
Here is the code I'm using for the custom cell class:
.h :
//
// RecommendationCell.h
// Tuneplug
//
// Created by Bill Labus on 6/21/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RecommendationCell : UITableViewCell {
UIImageView *artwork;
}
@property (nonatomic, retain) UIImageView *artwork;
@end
.m :
//
// RecommendationCell.m
// Tuneplug
//
// Created by Bill Labus on 6/21/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "RecommendationCell.h"
@implementation RecommendationCell
@synthesize artwork;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// 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
{
[super dealloc];
}
@end
(Note that I reduced the subviews to just the 'artwork' image view for now, to simplify figuring it out). Thanks for any help!
Unless I'm misunderstanding:
Try adding the IBOutlet tag.
IBOutlet UIImageView *artwork;
and
@property (nonatomic, retain) IBOutlet UIImageView *artwork;
This tag is a #define within Xcode that tells Interface Builder to recognize your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With