在我的应用中,我在表格 View 中添加了一个 slider ,即每一行都包含一个 slider ,它也可以正常工作。
但是当我滚动表格 View 时, slider 会重新加载,即每个显示我的起始位置而不是 slider 值。
//My code is as follow for slider in table cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier=[NSString stringWithFormat:@"CellIdentifier%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
return cell;
}
UISlider* theSlider = [[[UISlider alloc] initWithFrame:CGRectMake(174,12,120,23)] autorelease];
theSlider.maximumValue=99;
theSlider.minimumValue=0;
[cell addSubview:theSlider];
return cell;
}
我该如何解决这个问题??
最佳答案
您必须将 slider 值存储在数组等中,并根据 cellforrowatindexpath
中的数组值设置 slider 值
关于iphone - TableView 中的 slider 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14933667/