2011-12-04 12 views
8

Interface Builder(Storyboard)でカスタムUITableViewCellを作成し、#import CustomTableViewCell.h経由でプロジェクトにインポートしました。カスタムUITableViewCell(IB)のみが選択状態で表示されます

すべて正常に動作しますが、セルは選択された状態でのみ読み込まれます。

enter image description here

私は、セルが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で行をデザインしたいと思っています。解決策が必要です。

+0

UITableViewに行を設定する際に使用するcellForRowAtIndexPathメソッドのコードを投稿できますか? – reddersky

+0

答えを更新しました。 – DAS

+0

このセルは、別のペン先またはストーリーボードのテーブルビュー内のプロトタイプとして設計しましたか? – jrturton

答えて

16

わかりました...ここに起こって奇妙なこと... ;-)問題は、この行だった:

cell.textLabel.text = [NSString stringWithFormat:@"%@", [listOfItems objectAtIndex:indexPath.row]]; 

はそれを残しトリックをしました。私は別のUILabelを私のカスタムセルに追加しなければならなかった。標準UITableViewCell.textLabel.textを充填

結論

PrototypeCellsを上書きしているようです。

...あまりにもカスタマイズが痛いです。 ;-)

ありがとうございました! :)

+0

もう一度あなたに感謝します。 – DAS

+0

私は一般的には - デフォルトのセルスタイルを使用してサブビューを追加すると、これはおそらく何か目を引くものです。 – jrturton

+0

よろしくお願いいたします。それはちょうど私が別のセルスタイルの束を必要としたためです。 IBでそれらを視覚化する方が簡単です。 :) – DAS

0

IBに行かないことをお勧めします。ただ、プロパティとして、これらのコントロールを定義し、あなたのinit METHOD- initWithStyle(CustomTableViewCell.mファイル)で、デフォルトプロパティでUISliderを初期化:

UISlider *tempSlider = [[UISlider alloc] initWithFrame:frame]; 
tempSlider.selected = NO; 
//define other properties as well 
self.slider = tempSlider; 
[self addSubview:self.slider]; 
[tempSlider release]; 

あなたもなしにセル選択のスタイルを設定することができますほか。

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
+0

ありがとうございます。しかし、基本的に[this(click)](http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1)のように動作しなければなりません。誰も私の問題で何も変わらないこの行を使います: 'UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@" PlayerCell "];' – DAS

関連する問題