I don’t know why my segmentedControl isn’t working. If I press on it, I get the error
[AddDetailViewController segmentedControlIndexChanged:]: unrecognized selector sent to instance 0x71e0ad0
2012-11-05 16:25:51.380 proiect_caini[5903:c07] * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[AddDetailViewController segmentedControlIndexChanged:]: unrecognized selector sent to instance 0x71e0ad0’
I want when I click on the segmentedControl that is located in a cell of a table to get selected and to save that, so that I can display it.
Another problem is that I can’t locate this on the right side of the cell.
Here is my code:
This code is located in the cellForRowAtIndexPath, when I create the cell
case 8:{
cell.textLabel.text = @"Parinti";
//inputField.text =
lblParinti.text = dog?dog.parinti:@"";
segmentedControl1 = [[UISegmentedControl alloc] initWithItems: segmentItems];
// segmentedControl1.segmentedControlStyle = UISegmentedControlStyleBar;
// segmentedControl1.selectedSegmentIndex = 0;
[segmentedControl1 addTarget:self action:@selector(segmentedControlIndexChanged:) forControlEvents:UIControlEventValueChanged];
[cell addSubview:lblParinti];
[cell.contentView addSubview:segmentedControl1];
break;}
Here is the event that is triggered:
-(void) segmentedControlIndexChanged{
// reload data based on the new index
if (segmentedControl1.selectedSegmentIndex == 0) {
dog.parinti = @"Da";
} else if (segmentedControl1.selectedSegmentIndex == 1) {
dog.parinti = @"Nu";
}
//dog.parinti = [segmentedControl1 titleForSegmentAtIndex:segmentedControl1.selectedSegmentIndex];
[self.tableView reloadData];
}
Change your code in
cellForRowAtIndexPathfrom[segmentedControl1 addTarget:self action:@selector(segmentedControlIndexChanged:) forControlEvents:UIControlEventValueChanged];to
[segmentedControl1 addTarget:self action:@selector(segmentedControlIndexChanged) forControlEvents:UIControlEventValueChanged];If you use
@selector(segmentedControlIndexChanged:)you are saying that your method has an argument (which it doesn’t).