简体   繁体   English

使用uislider更改自定义tableview单元格标签的值

[英]Change the value of a custom tableview cell label with uislider

I am using a custum tableviewcell with a slider(m_CrtlSliderRating) and a label(m_CtrlLabelpositonName) . 我正在使用带有滑块(m_CrtlSliderRating)和标签(m_CtrlLabelpositonName)的custum tableviewcell。 I need to change the text of the label with respect to the slidervalue changed.Below is what i am tried 我需要相对于更改的slidervalue更改标签的文本。下面是我尝试的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustumCell_GroupSlider *cell    =   (CustumCell_GroupSlider *) [tableView dequeueReusableCellWithIdentifier:@"cellA"];
        if  (cell == nil)
        {
            NSArray *topLevelObjects            =   [[NSBundle mainBundle] loadNibNamed:@"CustumCell_GroupSlider" owner:Nil options:nil];

            for (id currentObject in topLevelObjects)
            {
                if  ([currentObject isKindOfClass:[UITableViewCell class]])
                {
                    cell =  (CustumCell_GroupSlider *) currentObject;

                    break;
                }
            }
        }

        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.m_CtllabelHeading.text =[ NSString stringWithFormat:@"%@", ObjIQuestions.m_strTitleEn];
            cell.m_CtrlLabelpositonName.tag=indexPath.row;
            cell.m_CrtlSliderRating.tag=indexPath.row;
            cell.m_CrtlSliderRating.minimumValue = 0.0;
            cell.m_CrtlSliderRating.maximumValue = (ObjIQuestions.m_muteArrOptions.count-1)*5;
            [cell.m_CrtlSliderRating addTarget:self
                                        action:@selector(GroupsliderValueChanged:)
                   forControlEvents:UIControlEventValueChanged];
}




-(void)GroupsliderValueChanged:(id)sender
{

    UISlider *ObjSlider = (UISlider *)sender;
    //How can i change the label value here i tried something but got error
}

Below is the custom class interface 下面是自定义类的界面

@interface CustumCell_GroupSlider : UITableViewCell
{

    __weak IBOutlet UISlider *m_CrtlSliderRating;
    __weak IBOutlet UILabel *m_CtllabelHeading;
    __weak IBOutlet UILabel *m_CtrlLabelpositonName;
}
@property (weak, nonatomic) IBOutlet UILabel *m_CtllabelHeading;
@property (weak, nonatomic) IBOutlet UISlider *m_CrtlSliderRating;
@property (weak, nonatomic) IBOutlet UILabel *m_CtrlLabelpositonName;

Please help me if anyone had experience with it. 如果有人有经验请帮助我。

You have a custom cell, so why not placing the 您有一个自定义单元格,为什么不放置

-(void)GroupsliderValueChanged:(id)sender
{
    // ---
    m_CtrlLabelpositonName.text = [NSString stringWithFormat:@"%f", m_CrtlSliderRating.value];
}

in the custom Cell? 在自定义单元格中? there you have also access to the label that is hold by this cell :) 在那里,您还可以访问此单元格保存的标签:)

-(void)GroupsliderValueChanged:(UISlider )*sender
{
     UITableViewCell *objCell = (UITableViewCell *)[yourTableView cellForRowAtIndexPath:sender.tag];
     objCell.m_CtllabelHeading.text = @"your text";

}

use 采用

-(void)GroupsliderValueChanged:(UISlider )*sender
    {
         CustumCell_GroupSlider *c = (CustumCell_GroupSlider *)[tableView cellForRowAtIndexPath:sender.tag]
         c.m_CtllabelHeading.text = @"Slider Value";      
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM