From my other question; Using UITableViewCell in a UITableView I’ve used the IB to create a custom cell. Heres how my code is at the moment:
ViewRoutes (Original Table)
.h
@interface ViewRoutes : UIViewController {
IBOutlet UITableView *tblRoute;
}
@property(nonatomic, retain) UITableView *tblRoute;
@end
.m
#import "ViewRoutes.h"
#import "ViewRoutesCell.h"
@implementation ViewRoutes
@synthesize tblRoute;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (NSInteger)
numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell * aCell = [tableView dequeueReusableCellWithIdentifier:@"ViewRoutesCell"];
if (aCell == nil)
{
NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"ViewRoutesCell" owner:self options:nil];
for (NSObject *anObj in arr) {
if([anObj isKindOfClass:[UITableViewCell class]]) {
aCell = (UITableViewCell *)anObj;
}
return aCell;
}
}
}
and the .xib just has a UITableView on it.
The ViewRoutesCell (What I want to be the custom cell)
.h
#import <UIKit/UIKit.h>
@interface ViewRoutesCell : UITableViewCell {
IBOutlet UITableViewCell *routesCell;
NSMutableArray *arryRouteText;
NSMutableArray *arryRouteImage;
IBOutlet UILabel *lblRouteText;
IBOutlet UILabel *lblRouteImage;
}
@property (nonatomic, retain) NSMutableArray *arryRouteText;
@property (nonatomic, retain) NSMutableArray *arryRouteImage;
@property (nonatomic, retain) UILabel *lblRouteText;
@property (nonatomic, retain) UILabel *lblRouteImage;
@end
The only thing i’ve done in the custom cell .m is synthesized the items
Then my custom cell xib i’ve got:



From here I get a little stuck, I can’t work out how to set the two label properties from my ViewRoutes.m (they will be coming from xml eventually, but for now just a mutablearray)
Am I doing this the right way?
Tom
Edit Just to let you know i’m loading the image string to a label for now, will be an image later
In the declaration of
you’re creating a
UITableViewCellobject. This does not know about your custom defined labels. You should change it to:Then, in the
ifclause, you should changeto
This will make the compiler recognize the object as being one of your specific cells, allowing you to access the label properties.
Hope this helps!