uitableview - Determining the state of a UISwitch when the UITableCell it is on is clicked -


I'm a new one for iOS programming and I have a problem. I have a table view that I will call in the cell phone Loads dynamically in each cell with a UISwitch

  UISwitch * mySwitch = [[UISwitch alloc] init]; Self.myNewSwitch = mySwitch; [MySwitch release]; [See cell set Aesparent: Self Manis Switch]; [(UISwitch *) cell.accessoryView addTarget: Self-action: @Selector (changeState :) forControlEvents: UIControlEventValueChanged];   

This works fine when I click on the switch, the code keeps running in the change.

Here's where my problem is when the user presses a cell in the table, then I want to see what is going on in the switch (on or off). My problem is that I can not understand how it was decided that in the didSelectRowAtIndexPath code I can determine the correct cell, but when I search using Google, how to use the switch on that cell. Here is my code SelectionRowAtIndexPath:

  - (zero) tableview: (UITableView *) table view was SelectionRowAtIndexPath: (NSIndexPath *) indexPath {// If the on / off switch is on, go to the check page. If it's closed, do not do anything UITableViewCell * cell = [tableView cellForRowAtIndexPath: indexPath]; // Set the switch status here. UISwitch * theSwitch; Thewitch = ??????? // & lt; - What should I do ??? If (theSwitch.isOn) {// test defines view controller, Probes * detailViewController = [[check alloc] initWithNibName: @ "check" bundle: zero]; // pass the IP address detailViewController.lblIPAddr = cell.detailTextLabel.text; // Pass the selected object in the new view controller. Navigation Controller Push ViewController: Animated Detail Viewer: Yes]; [DetailViewController release]; } // Unselect this row [deselect tableviewAtindex: indexpath animated: yes]; }   

Any help / code will be useful.

-NCGrimbo

  - (zero) table view: (UITableView * ) Table view was selected: Endand xp: (NSIndexPath *) indexPath {// If the ON / OFF switch is ON, go to the test page and if OFF, do not do anything then UITableViewCell * cell = [tableView cellForRowAtIndexPath: indexPath]; // Set the switch status here. UISwitch * theSwitch = (UISwitch *) cell.accessoryView; If (theSwitch.isOn) {// test defines view controller, Probes * detailViewController = [[check alloc] initWithNibName: @ "check" bundle: zero]; // pass the IP address detailViewController.lblIPAddr = cell.detailTextLabel.text; // Pass the selected object in the new view controller. Navigation Controller Push ViewController: Animated Detail Viewer: Yes]; [DetailViewController release]; } // Unselect this row [deselect tableviewAtindex: indexpath animated: yes]; }   

But I do not know why you are using,

  UISwitch * mySwitch = [[UISwitch alloc] init]; Self.myNewSwitch = mySwitch; [MySwitch release]; [See cell set Aesparent: Self Manis Switch];   

Every time you move to the new UITB, you automatically The ManifestSite is the same UISwitch.

Comments