так что обычно вы создаете UITableViewController, который делегирует, как работает таблица (это где методы numberOfSectionsInTableView, numberOfSectionsInTableView и т.д.) чтобы сделать сами ячейки разными, то по умолчанию вам нужно создать подкласс UITableViewCell
customcell.h
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell {
UILabel *primaryLabel;
UIImageView *myImageView;
}
@property (nonatomic, retain) UILabel *primaryLabel;
@property (nonatomic, retain) UIImageView *myImageView;
@end
customcell.m
#import "CustomCell.h"
@implementation CustomCell
@synthesize primaryLabel,myImageView;
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
primaryLabel = [[UILabel alloc]init];
primaryLabel.textAlignment = UITextAlignmentLeft;
primaryLabel.font = [UIFont systemFontOfSize:20];
primaryLabel.backgroundColor = [UIColor blackColor];
primaryLabel.textColor = [UIColor redColor];
myImageView = [[UIImageView alloc]init];
[self.contentView addSubview:primaryLabel];
[self.contentView addSubview:myImageView];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+10 ,0, 300, 40);
myImageView.frame = frame;
frame= CGRectMake(boundsX+70 ,5, 200, 25);
primaryLabel.frame = frame;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[myImageView release];
[primaryLabel release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
}
затем вернитесь к вашему UITableViewController: метод cellforrowatindexpath, вы должны выделить свою пользовательскую ячейку
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSInteger row = [indexPath row];
NSString *pathString= [snowBoardArray objectAtIndex:row];
NSString *string2= @"Cell";
pathString = [pathString stringByAppendingString:string2];
cell.primaryLabel.text=[snowBoardArray objectAtIndex:row];
NSString *filePath = [[NSBundle mainBundle] pathForResource:pathString ofType:@"png"];
UIImage *theImage = [[UIImage alloc] initWithContentsOfFile:filePath];
cell.myImageView.image = theImage;
[theImage release];
return cell;
}