Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a UISegmentedControl button to a toolbar within UITableViewController
    primarykey
    data
    text
    <p>I am trying to add a toolbar with a <code>UISegmentedControl</code> appearing at the bottom of my view. I am within a <code>UITableViewController</code>, which is embedded in a navigation controller which is embedded in tabbar controller. Usual drill down stuff. I want this toolbar to only appear in this particular tab view. I use storyboards.</p> <p>I tried creating a segmented control in the IB (storyboard), configuring its items and placing it within the viewcontroller catalog (that gray bar below the viewcontroller in the storyboard) </p> <p><a href="http://i47.tinypic.com/5yg8pj.png" rel="nofollow noreferrer">storyboard http://i47.tinypic.com/5yg8pj.png</a></p> <p>adding a ref outlet of this segmented control to my viewcontroller.h then unhiding the navcontroller toolbar and trying to add this item</p> <pre><code>self.navigationController.toolbarHidden = NO; UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:myOutletSegmentedControl]; self.navigationController.toolbar.items = [NSArray arrayWithObjects:segmentBarItem, nil]; </code></pre> <p>So my <code>myOutletSegmentedControl</code> is uninitialized, even though I fully configured it in IB. So tried programmatically:</p> <pre><code>self.navigationController.toolbarHidden = NO; UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems: [NSArray arrayWithObjects:@"a-b",@"b-a",nil]]; [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; segmentedControl.frame = self.navigationController.toolbar.frame; segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; segmentedControl.momentary = NO; UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl]; self.navigationController.toolbar.items = [NSArray arrayWithObjects:segmentBarItem, nil]; </code></pre> <p>Now getting a toolbar at the bottom but with no items..</p> <p>I even tried creating the whole toolbar -> child button -> child segmented control in IB and outletting it, then doing:</p> <pre><code> self.navigationController.toolbar = myNewOutletToolbar; </code></pre> <p>Still no go. I do prefer to use the storyboard/IB to create my UI, but I am pulling my hair out on it...</p>
    singulars
    1. This table or related slice is empty.
    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. 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