Interface Builder(Storyboard)でカスタムUITableViewCell
を作成し、#import CustomTableViewCell.h
経由でプロジェクトにインポートしました。カスタムUITableViewCell(IB)のみが選択状態で表示されます
すべて正常に動作しますが、セルは選択された状態でのみ読み込まれます。
私は、セルがinitによってすべての行にロードすることにしたいです。
P.S.スライダーとテキストフィールドの接続は正常に動作します。私はすべてのIBコネクションも作りました。
CustomTableViewCell.m
#import "CustomTableViewCell.h"
@implementation CustomTableViewCell
@synthesize sliderLabel, slider;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (IBAction)getSliderValuesWithValue:(UISlider *)sender
{
sliderLabel.text = [NSString stringWithFormat:@"%i/100", (int) roundf(sender.value)];
}
@end
Further Code
- (CustomTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Kriterium";
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [NSString stringWithFormat:@"%@", [listOfItems objectAtIndex:indexPath.row]];
return cell;
}
P.S.上記のメソッドでButtonなどをプログラムで追加すると機能します。しかし、私はIBで行をデザインしたいと思っています。解決策が必要です。
UITableViewに行を設定する際に使用するcellForRowAtIndexPathメソッドのコードを投稿できますか? – reddersky
答えを更新しました。 – DAS
このセルは、別のペン先またはストーリーボードのテーブルビュー内のプロトタイプとして設計しましたか? – jrturton