Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Where did you pull this <code>-numberForRowsInSection:</code> method from? As far as I (and the documentation) know, it doesn't exist and has never existed as a method of UITableView. Guessing is going to get you nowhere, much less inventing methods from thin air.</p> <p>Perhaps you should review some tutorials that cover the basics of using UITableView before you attempt this. I doubt someone is going to take the time to write you a full class to do this and put it in an answer, and you'll be much better off in the long run if you don't simply try to copy/paste code that you don't understand. There exists much documentation and examples that cover UITableView, and that's just considering what's available from Apple - UITableView is such a frequently used class that searching Google for something like "UITableView tutorial" is going to give you pages and pages of results.</p> <p>I will give you a quick overview of what you would need to do, though: 1. Of course, you can start with the UITableViewController template in Xcode and start customizing it to fit your requirements...two sections, however many rows per section, etc, determining that based on some model-level objects if necessary.</p> <ol start="2"> <li><p>You'll need to either create a custom UITableViewCell subclass or customize the default UITableViewCell layout a good bit (at least by adding a UISwitch subview) when you create new cell objects in <code>tableView:cellForRowAtIndexPath:</code>. </p></li> <li><p>The UISwitch should be configured to send a message to your view controller when the switch's value changes using <code>-[UIControl addTarget:action:forControlEvents:]</code> for the <code>UIControlEventValueChanged</code> event.</p></li> <li><p>In your implementation of the action method for this switch value change, you'll need to implement logic to determine whether rows should be added or subtracted, and then actually add or subtract the rows. You can use <code>beginUpdates</code>/<code>endUpdates</code>, <code>insertRowsAtIndexPaths:withRowAnimation:</code> and <code>deleteRowsAtIndexPaths:withRowAnimation:</code> to have the nice smooth row animation behavior instead of simply calling <code>reloadData</code>.</p></li> </ol>
 

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