我创建了一个带有 UISegmentedControl 的自定义单元格,并像这样加载了单元格,
static NSString *CellIdentifier = @"Cell";
SegmentedCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *cells =[[NSBundle mainBundle] loadNibNamed:@"SegmentedCell" owner:nil options:nil];
for (UIView *view in cells)
{
if([view isKindOfClass:[UITableViewCell class]])
{
cell = (SegmentedCell *)view;
[cell.SegmentedControl addTarget:self
action:@selector(segmentedControlChanged:)
forControlEvents:UIControlEventValueChanged];
}
}
}
cell.textLabel.text = @"Sample";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
自定义单元格成功加载,我得到了 SegmentedControl 的操作。但是当我滚动表格视图时,SegmentedControl 的状态发生了变化。