我正在制定一个看起来像这样的程序:
有一个表视图i,有一个自定义表视图单元格 . 自定义视图单元格上有一个UISlider,Label和Button
现在的问题是当我滑动Cell的UISlider:0而不是Cell的UISlider:12(或更高版本的Cell)自动分配Cell:0的UISlider值(感谢ARC ...... !!) .
现在任何人都有一个解决方案,以便后一个单元格的UISlider doest改变,同时我改变上部单元格的值 .
附:当我在Cell上分配UiSlider值时:0并向上和向下滚动它会自动随机Cell的UISlider值正在改变 .
Google Drive项目链接:Slider Program
我正在使用xCode 5和iOS SDK 7 .
谢谢阅读 .
编辑:cellForRowAtIndexPath方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableCell = @"Cell";
CustomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableCell];
if (cell == nil) {
cell = [[CustomeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableCell];
}
NSString *strName = [NSString stringWithFormat:@"Cell : %d",indexPath.row];
// NSLog(@"strName :%@ , SliderValue : %d",strName , (int)cell.mySlider.value);
for (int i = 0; i < arrSlider.count; i++) {
NSString *strTag = [NSString stringWithFormat:@"%@",[[arrSlider objectAtIndex:i]valueForKey:@"tag"]];
NSString *myIndexPath = [NSString stringWithFormat:@"%d",indexPath.row];
if([strTag isEqualToString:myIndexPath])
{
NSString *strValue = [NSString stringWithFormat:@"%@",[[arrSlider objectAtIndex:i]valueForKey:@"value"]];
cell.mySlider.value = [strValue floatValue];
NSLog(@"Tag Value : %@ , value %f", strTag , [strValue floatValue]);
}
}
[cell.btnCell setTitle:strName forState:UIControlStateNormal];
cell.btnCell.tag = indexPath.row;
cell.mySlider.tag = indexPath.row;
[cell.mySlider addTarget:self action:@selector(customSliderValue:) forControlEvents:UIControlEventValueChanged];
[cell.btnCell addTarget:self action:@selector(customeBtnClicked:) forControlEvents:UIControlEventTouchDown];
return cell;
}
3 回答
使用
NSMutableDictionary
保存滑块的值然后从cellForRowAtIndexPath
方法更新它我发布更改只需在项目中进行更改在
ViewCOntroller.h
文件中在
ViewController.m
文件中在
CustomeTableViewCell.h
文件中在
CustomeTableViewCell.m
文件中希望这有助于你.. :)
您不需要检查(设置)Cell的所有数据源,我的意思是, No need of for loop inside the cellForRowAtIndexPath . just remove it and will work fine .
试试这个适用于我的代码: