我在Interface Builder(故事板)做了一個自定義的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;
}
附:如果我在上面的方法中編程添加一些按鈕等,它的工作原理。但我想要在IB中設計行。必須有一個解決方案。
您可以發佈與填充行的UITableView時使用您的cellForRowAtIndexPath方法的代碼? – reddersky
我更新了我的答案。 – DAS
您是否在單獨的筆尖中設計了該單元格,或者在故事板中的表格視圖中將其設計爲原型? – jrturton