I am a newbie in the world of Objective-C and iOS coding so I ll appreciate a little bit of help.
Here is my issue. I ve got a UITableView with a UISegmentedControl. This one has 6 different segments which modify the content of the table by modifying an NSMutableArray. I managed to do that so I m already pretty proud of me but still the newbie curse is back today. I want to implement checkmarks in order to select cells and pass the cells data to another UITableView. The first issue is that I ve got my checkmarks but I click on a different segment the data are updated but the checkmarks from the previous segment remain. How to address this problem.
Second what is the best way to pass data from all of the segment of this UITableView to another tableview by selecting the cells?
Here is my UITableViewController.h
@class MesExercicesViewController;
@protocol MesExercicesViewControllerDelegate <NSObject>
- (void) mesExercicesViewControllerDidCancel:
(MesExercicesViewController *) controller;
- (void) mesExercicesViewControllerDidSave:
(MesExercicesViewController *)controller;
@end
@interface MesExercicesViewController : UITableViewController {
NSMutableArray *exercicesList;
UISegmentedControl *segment;
}
- (IBAction)segmentChange;
@property (nonatomic, retain) IBOutlet UISegmentedControl *segment;
@property (nonatomic, weak) id <MesExercicesViewControllerDelegate> delegate;
- (IBAction)cancel:(id)sender;
- (IBAction)done:(id)sender;
@end
And here is the code of the UISegmentedControl in the UITableViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
exercicesList = [NSMutableArray arrayWithObjects:
@"A",@"A1",@"A2",@"A3",@"A4",@"A5",@"A6",@"A7", nil];
}
- (IBAction)segmentChange {
if (segment.selectedSegmentIndex == 0) {
exercicesList = [NSMutableArray arrayWithObjects:@"A",@"A1",@"A2",@"A3",@"A4",@"A5",@"A6", nil];
[[self tableView]reloadData];
} else if (segment.selectedSegmentIndex == 1) {
exercicesList = [NSMutableArray arrayWithObjects:@"C",@"C1",@"C2",@"C3",@"C4", nil];
[[self tableView] reloadData];
} else if (segment.selectedSegmentIndex == 2) {
exercicesList = [NSMutableArray arrayWithObjects:@"E",@"E1",@"E2",@"E3",@"E4",@"E5",@"E6",@"E7",@"F",@"F1", nil];
[[self tableView] reloadData];
} else if (segment.selectedSegmentIndex == 3) {
exercicesList = [NSMutableArray arrayWithObjects:@"I",@"I1",@"I2",@"I3",@"I4",@"I5",@"I6",@"I7",@"I8",@"J", nil];
[[self tableView] reloadData];
} else if (segment.selectedSegmentIndex == 4) {
exercicesList = [NSMutableArray arrayWithObjects:@"L",@"M",@"M1",@"N",@"N1", nil];
[[self tableView] reloadData];
} else if (segment.selectedSegmentIndex == 5) {
exercicesList = [NSMutableArray arrayWithObjects:@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z", nil];
[[self tableView] reloadData];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
//reflect selection in data model
}else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
//reflect the deselection in data model
}
Thank you very much for your help in advance