Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update for iOS 7</strong></p> <p><a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006801-CH3-DontLinkElementID_2" rel="nofollow noreferrer">Apple docs for UIActionSheet</a>: <code>UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy</code></p> <p>I recommend against trying to customize the contents of an ActionSheet, as it can lead to serious invalid context errors in iOS 7. I just spent a few hours working through this problem and ultimately decided to take a different approach. I replaced the call to show the action sheet with a modal view controller containing a simple tableview. </p> <p>There are many ways to accomplish this. Here's one way that I just implemented in a current project. It's nice because I can reuse it between 5 or 6 different screens where I all users to select from a list of options.</p> <ol> <li>Create a new UITableViewController subclass, <code>SimpleTableViewController</code>.</li> <li>Create a UITableViewController in your storyboard (embedded in a navigation controller) and set its custom class to SimpleTableViewController.</li> <li>Give the navigation controller for SimpleTableViewController a Storyboard ID of "SimpleTableVC". </li> <li>In SimpleTableViewController.h, create an NSArray property that will represent the data in the table.</li> <li>Also in SimpleTableViewController.h, create a protocol <code>SimpleTableViewControllerDelegate</code> with a required method <code>itemSelectedatRow:</code>, and a weak property called delegate of type <code>id&lt;SimpleTableViewControllerDelegate&gt;</code>. This is how we will pass the selection back to the parent controller.</li> <li>In SimpleTableViewController.m, implement the tableview data source and delegate methods, calling <code>itemSelectedatRow:</code> in <code>tableView:didSelectRowAtIndexPath:</code>.</li> </ol> <p>This approach has the added benefit of being fairly reusable. To use, import the SimpleTableViewController class in your ViewController.h, conform to the SimpleTableViewDelegate, and implement the <code>itemSelectedAtRow:</code> method. Then, to open the modal just instantiate a new SimpleTableViewController, set the table data and delegate, and present it.</p> <pre><code>UINavigationController *navigationController = (UINavigationController *)[self.storyboard instantiateViewControllerWithIdentifier:@"SimpleTableVC"]; SimpleTableViewController *tableViewController = (SimpleTableViewController *)[[navigationController viewControllers] objectAtIndex:0]; tableViewController.tableData = self.statesArray; tableViewController.navigationItem.title = @"States"; tableViewController.delegate = self; [self presentViewController:navigationController animated:YES completion:nil]; </code></pre> <p>I create a simple example and <a href="https://github.com/kmc239/KMCModalTableView" rel="nofollow noreferrer">posted it on github</a>.</p> <p>Also see <a href="https://stackoverflow.com/questions/19129091/showing-actionsheet-causes-cgcontext-invalid-context-errors">Showing actionsheet causes CGContext invalid context errors</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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