Home > CodeSnippets, Interface Builder, iOS, Xcode > Customized UITableViewCell

Customized UITableViewCell

Eine leere xib erstellen und im Interface Builder die UITableViewCell zusammenbauen.

Eine neue Klasse, die von UITableViewCell abgeleitet ist, erstellen und die benötigten Outlets definieren:


#import 
@interface CustomCell : UITableViewCell {

	IBOutlet UILabel *label1;
	...
}
@property (assign) UILabel * label1;
...
@end

#import "CustomCell.h"
@implementation CustomCell
@synthesize label1;

Dann im Interface Builder den Typ der Cell auf die Klasse CustomCell setzen und die Outlets verbinden.

Im Controller der UITableView:


#import "CustomCell.h"

-(UITableViewCell *) tableView:(UITableView *) tableView 
  cellForRowAtIndexPath:(NSIndexPath *) indexPath {

static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *)
  [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
	NSArray *array = [[NSBundle mainBundle]
  loadNibNamed:@"CustomCell" owner:self options:nil];
	cell = [array lastObject];
}
cell.label1.text = @"some text";
…
}

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: