Sorry. I declared the switch in my flipsideview header:
@protocol FlipsideViewControllerDelegate;
@interface FlipsideViewController : UIViewController {
id <FlipsideViewControllerDelegate> delegate;
NSMutableArray *list;
UIView *myView;
UISwitch *switch1;
}
@property (nonatomic, copy, readwrite) NSMutableArray *list;
@property (nonatomic, retain) UIView * myView;
@property (nonatomic, retain)UISwitch *switch1;
@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)cancel:(id)sender;
- (IBAction)save:(id)sender;
@end
@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end
Then I have the tableview together with the bar, in the flipsideview. Removed the code that isn't relevant to the question:
- (void)viewDidLoad {
UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, 320, 416) style:UITableViewStyleGrouped];
tableView.dataSource = self;
tableView.allowsSelection = FALSE;
[self.view addSubview:tableView];
[super viewDidLoad];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,0,0) reuseIdentifier:@"CellIdentifier"] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if(indexPath.row == 0) {
cell.text = @"ON/OFF";
cell.accessoryView = [[switch1 alloc] initWithFrame:CGRectZero]; //Doesnt work, and can't reference!!!
}
else {
cell.accessoryView = [[UITextField alloc] initWithFrame:CGRectMake(0,0,284,30)];
}
return cell;
}
If I replace the commented line with:
cell.accessoryView = [[UISwitch alloc] initWithFrame:CGRectZero];
It of course works, but then I can't reference the value of it later in another method like this:
- (IBAction)save:(id)sender {
if (option1.on == YES ) {
[self.delegate flipsideViewControllerDidFinish:self];
}
}