Note that there are some explanatory texts on larger screens.

plurals
  1. PONot Sure How to Update Bool Values in Plist from UISwitch in UITableViewCell
    text
    copied!<p>I have a table with four rows, each having a title and switch as an accessory. I would like for the plist Boolean value to be updated when the corresponding switch is tapped.</p> <p>Plist:</p> <pre><code>&lt;array&gt; &lt;dict&gt; &lt;key&gt;Bools&lt;/key&gt; &lt;array&gt; &lt;false/&gt; &lt;false/&gt; &lt;false/&gt; &lt;false/&gt; &lt;/array&gt; &lt;key&gt;Strings&lt;/key&gt; &lt;array&gt; &lt;string&gt;String0&lt;/string&gt; &lt;string&gt;String1&lt;/string&gt; &lt;string&gt;String2&lt;/string&gt; &lt;string&gt;String3&lt;/string&gt; &lt;/array&gt; &lt;/dict&gt; &lt;/array&gt; </code></pre> <p>Here are the data source methods:</p> <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; { return [allergens count]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; { return [[[allergens objectAtIndex: section] objectForKey: @"Strings"] count]; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; { return @"Header"; } </code></pre> <p>Here is my switch, with selector: switchToggled</p> <pre><code>UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero]; cell.accessoryView = switchView; [switchView addTarget:self action:@selector(switchToggled:) forControlEvents: UIControlEventTouchUpInside]; </code></pre> <p>Below is the IBAction method. I can successfully get the <code>switch tapped</code> to appear in the log, so I know everything works. I am just not sure how to get the correct Boolean value to be updated.</p> <pre><code>- (IBAction)switchToggled:(id)sender { NSLog(@"switch tapped"); } </code></pre> <p>Any help is appreciated! Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload