I am using a custum tableviewcell with a slider(m_CrtlSliderRating) and a label(m_CtrlLabelpositonName) . I need to change the text of the label with respect to the slidervalue changed.Below is what i am tried
- (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";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.