Iphone 从单元格内的UISlider获取值

Iphone 从单元格内的UISlider获取值,iphone,ios,uitableview,uislider,Iphone,Ios,Uitableview,Uislider,我有一个带有自定义单元格的tableView,每个单元格都有一个UISlider 现在我想创建一个方法来获取这些UISlider的值,但我不知道如何访问每个单元格及其滑块值 提前谢谢 嗯,几乎没有可能: 1保留对UITableViewController中所有单元格的引用 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //S

我有一个带有自定义单元格的tableView,每个单元格都有一个UISlider

现在我想创建一个方法来获取这些UISlider的值,但我不知道如何访问每个单元格及其滑块值


提前谢谢

嗯,几乎没有可能:

1保留对UITableViewController中所有单元格的引用

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      //Set up your cell

      [[self allCells] addObject:cell];
      return cell;
}

-(void)getSliderValues {
    for(CustomCell *cell in [self allCells]){
        //Here is your cell
        cell;
    }
}
在tableView:cellForRowAtIndexPath:中,在返回单元格之前,将其作为UITableViewController上的属性添加到数组中

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      //Set up your cell

      [[self allCells] addObject:cell];
      return cell;
}

-(void)getSliderValues {
    for(CustomCell *cell in [self allCells]){
        //Here is your cell
        cell;
    }
}
2使用tableView:cellForRowAtIndexPath:


请注意,在这种方法中,如果您使用的是重用标识符,则可能无法获得您想要/需要的单元格。

嗯,很少有可能:

1保留对UITableViewController中所有单元格的引用

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      //Set up your cell

      [[self allCells] addObject:cell];
      return cell;
}

-(void)getSliderValues {
    for(CustomCell *cell in [self allCells]){
        //Here is your cell
        cell;
    }
}
在tableView:cellForRowAtIndexPath:中,在返回单元格之前,将其作为UITableViewController上的属性添加到数组中

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      //Set up your cell

      [[self allCells] addObject:cell];
      return cell;
}

-(void)getSliderValues {
    for(CustomCell *cell in [self allCells]){
        //Here is your cell
        cell;
    }
}
2使用tableView:cellForRowAtIndexPath:


请注意,在这种方法中,如果您使用的是重用标识符,则可能无法获得您想要/需要的单元格。

首先为每个滑块添加一个标记,这样您就不会知道哪个滑块是哪个:

slider.tag=0//可以是任何唯一的整数

然后注册滑块更改的方法:

[滑块添加目标:自我操作:@selectorsliderUpdate:forControlEvents:UIControlEventValueChanged]

最后用你的方法

-(void)sliderUpdate:(UISlider *)sender {
    int value = sender.value;
    int tag = sender.tag;
}

标记现在将与您以前使用的唯一整数相同。这是一种识别元素的方法。

首先在每个滑块上添加一个标记,以便确定哪个滑块是哪个:

slider.tag=0//可以是任何唯一的整数

然后注册滑块更改的方法:

[滑块添加目标:自我操作:@selectorsliderUpdate:forControlEvents:UIControlEventValueChanged]

最后用你的方法

-(void)sliderUpdate:(UISlider *)sender {
    int value = sender.value;
    int tag = sender.tag;
}

标记现在将与您以前使用的唯一整数相同。这是一种识别元素的方法。

我应该在幻灯片更新中的标签之间切换吗?或者如果我通过我的13个标签PI实际上会使用一个循环:对于int i=0;i<细胞数;i++{如果i==slider.tag{//这是与此slider相对应的单元格}}我应该在该sliderUpdate内的标记之间切换吗?或者如果我通过我的13个标签PI实际上会使用一个循环:对于int i=0;i<细胞数;i++{if i==slider.tag{//这是对应于此slider的单元格}