iPhoneOS SDK – Subclassing a UITableview
20/04/2010This is more of a personal reminder about how to subclass a UITableViewCell, but this should be useful to the discerning reader. All the edits required to subclass are the lower code line in each section, the above is the default code (commented out).
.m file Modifications
#import “UITableViewCellFixed.h”
// Below is first the original then the subclassed
//UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:CellIdentifier];
UITableViewCellFixed *cell = (UITableViewCellFixed *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// Below is first the original then the subclassed
//cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
cell = [[[UITableViewCellFixed alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
//Cell Accessories
//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
Then the subclass file looks like:
// UITableViewCellFixed.h
//
#import <UIKit/UIKit.h>
@interface UITableViewCellFixed : UITableViewCell {
}
@end
//
// UITableViewCellFixed.m
//
#import “UITableViewCellFixed.h”
@implementation UITableViewCellFixed
- (void) layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = CGRectMake(self.textLabel.frame.origin.x,
4.0,
self.textLabel.frame.size.width,
self.textLabel.frame.size.height);
self.detailTextLabel.frame = CGRectMake(self.detailTextLabel.frame.origin.x,
8.0 + self.textLabel.frame.size.height,
self.detailTextLabel.frame.size.width,
self.detailTextLabel.frame.size.height);
}
@end
No comments yet.