[英]iPhone Custom cell with UISegmentedControl
I have created a custom cell with a UISegmentedControl on it and loaded the cell like, 我创建了一个带有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;
The custom cell successfully loaded and I get the action of the SegmentedControl. 自定义单元已成功加载,我得到了SegmentedControl的操作。 But when I scroll the table view, state of the SegmentedControl is changed.
但是,当我滚动表视图时,SegmentedControl的状态会更改。
When you scroll a tableview that uses dequeueReusableCellWithIdentifier, you aren't actually saving all the different cells. 滚动使用dequeueReusableCellWithIdentifier的表视图时,实际上并没有保存所有不同的单元格。 To fix your problem you need to implement a few things.
要解决您的问题,您需要执行一些操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.