I have a custom UITableViewCell that has a UISegmentedControl object. My UITableView (questionnaire form) has 6 of this custom cell (6 segmented controls). I am having trouble getting the selectedSegmentIndex of the segment controls. My guess is that the cells are being released after the table is generated. I am getting the values using the following code:
MyCustomCell *q1 = (MyCustomCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndex:0]];
int segmentIndex = (int) q1.segmentedController.selectedSegmentIndex;
the int segmentIndex is always giving the same value of 0 no matter what the selected index is.
You must use the right method to initialize your index path for the section and row you want use, otherwise
rowandsectionproperties won’t be correctly set, and you will get the same cell each time :+(NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section;.The code looks like :
You could also consult : NSIndexPath UIKit Additions Reference for more information.