Getting data from UITableView
Posted
by Tejaswi Yerukalapudi
on Stack Overflow
See other posts from Stack Overflow
or by Tejaswi Yerukalapudi
Published on 2010-04-06T18:34:12Z
Indexed on
2010/04/07
0:23 UTC
Read the original article
Hit count: 1007
iphone
Hi,
I have a few custom UITableViewCells -
http://img11.imageshack.us/i/customfacilitiescell.png/
which are added to this UIViewController -
http://img189.imageshack.us/i/facilitycontroller.png/
Now, on clicking a button in the controller, I'd like to get the on/off status of all the UISwitches in the controller.
Thanks,
Teja
Edit:
I've made a few edits, but I still can't figure out how to do this.
My program structure currently - A CustomCell.xib that looks like this - http://img11.imageshack.us/i/customfacilitiescell.png/
A CustomCellController that a subclass of UITableViewCell that has the IBOutlets for the labels and switches from above.
Now I have a UIViewController<UITableViewDataSource, UITableViewDelegate>
(Say, Screen1Controller) which looks like - http://img189.imageshack.us/i/facilitycontroller.png/
The tableviewcell is being created like this -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *Id= @"CustomFacilitiesCell";
CustomFacilitiesCellController *cell = (CustomFacilitiesCellController *)[tableView dequeueReusableCellWithIdentifier:Id];
if(cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomFacilitiesCell" owner:self options:nil];
for (id oneObject in nib) {
if([oneObject isKindOfClass:[CustomFacilitiesCellController class]])
cell = (CustomFacilitiesCellController *) oneObject;
}
}
NSUInteger row = [indexPath row];
CustomFacilitiesCellController *rowData = (CustomFacilitiesCellController *)[self.facilities objectAtIndex:row];
cell.facname.text = rowData.facname.text;
cell.FacID.text = rowData.FacID.text;
cell.facSwitch = [(CustomFacilitiesCellController *)rowData facSwitch];
UISwitch *temp = cell.facSwitch;
[(UISwitch *)[cell facSwitch] addTarget:self action:@selector(facSwitchOptionChanged:) forControlEvents:UIControlEventValueChanged];
cell.facSwitch.on = NO;
//cell.facSwitch.enabled = FALSE;
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
- (IBAction) facSwitchOptionChanged:(id) sender {
int i=0;
}
In particular, my problem is that the facSwitchOptionChanged()
isn't getting called.
Thanks again for the help, Teja.
© Stack Overflow or respective owner