問題の解決策を探している場合は、プログラムでカスタムセルを作成することをお勧めします。
私はあなたを段階的に説明しています。これはあなたを助けるでしょう。
したがって、UITableViewCell
から継承するクラスを作成し、必要なコンポーネントをtabelCellに追加します。
.hファイルは次のようになります。
// -------- ------- 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 < <
とあなたのm個のファイルがこの
// -------- ------- 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
}
// -------- END- ------ < <
これで、このカスタムセルを他のクラスで再利用する準備が整いました。要件ごとに変更することもできます。 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;
}
これはあなたを助けることを願っています。
1 .Also take a look on link tutorial.
2. A Closer Look at Table View Cells
OOのコンテキストで考えると、私は重複を避けようとしていました。 – Ans