Jeśli szukasz innego rozwiązania problemu, to proponuję programowo utworzyć niestandardową komórkę.
Wyjaśniam ci krok po kroku, to ci pomoże.
Stwórz więc klasę, która odziedziczy po UITableViewCell
, i dodaj komponenty, które są potrzebne w Twojej tabelce.
tak, aby plik .h wyglądał następująco.
START // -------- ------- >>
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell{
UIButton *btn1;
UIButton *btn2;
UIButton *btn3;
}
@property(nonatomic , retain) UIButton *btn1;
@property(nonatomic , retain) UIButton *btn2;
@property(nonatomic , retain) UIButton *btn3;
@end
// ------- ------- < END <
i Twoja.m plik będzie wyglądać następująco
// -------- ------- START >>
#import "CustomCell.h"
@implementation CustomCell
@synthesize btn1, btn2, btn3;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//----frame the components as per your project req.----
btn1 = [[UIButton alloc] initWithFrame:CGRectMake(1, 1, 85, 70)];
[self.contentView addSubview:btn1];
btn2 = [[UIButton alloc] initWithFrame:CGRectMake(100, 1, 85, 70)];
[self.contentView addSubview:btn2];
btn3 = [[UIButton alloc] initWithFrame:CGRectMake(195,1, 85, 70)];
[self.contentView addSubview:btn3];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
// -------- końcowych ------ < <
Teraz jesteś gotowy do ponownego użycia tej niestandardowej komórki w innych klasach. a także może modyfikować je zgodnie z wymaganiami.
Teraz w cellForRowAtIndexPath >>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
[cell.btN1 setImage:[UIImage imageNamed:@"YOUR IMAGE NAME"] forState:UIControlStateNormal]; // YOU CAN MAKE CHANGES HERE.
................// remaining logic goes here
return cell;
}
nadzieję, że to pomoże Ci.
1 .Also take a look on link tutorial.
2. A Closer Look at Table View Cells
Myśląc w kontekście OO, starałem się uniknąć powielania; – Ans