How to implement more than one controller in objective C - objective-c

First of all I don't know If controller is the right word. What I want to achieve is this.
#interface ClubViewController : CoreDataTableViewController :NRGridViewController
{
I know that this is not possible in objective-C. But is there a way to work around this?
Because I want to use CoreDateTableViewController and NRGridViewController.
Kind regards
Stef
EDIT
This is how my storyboard Hierarchy looks like.
-ViewController
-TableView
-View
-TableViewCell
So I have a tableview Controller but above this tableview controller you find a small view with three buttons. When I push on button 1 I want to take the tableview away and draw a gridView with the NRGridview Controller. But when I push on button 2 and 3 I fill up my tableview using the CoreDataTableViewController.
I hope this explains more my problem.

I think one way to do this is with a container view with a container view controller inside it. That container controller would have 2 child controllers which would be your CoreDateTableViewController and NRGridViewController. I've implemented something like this, and I can show you some code if you're interested.
After Edit: In a test app, I started with a single view template and a storyboard. I added two buttons to the top of the view and a container view to the bottom half of the view (this first controller is of class ViewController). I then dragged out a new view controller, and control dragged from the container view to the new controller and chose the "embed segue" (this will resize the view to be the same size as the container view). The class of this controller was changed to my subclass, ContainerController. I then created 2 more controllers for the 2 views that will be managed by the container controller (the views need to have their size set to "freeform" in IB so you can set the size to be the same as the container view). Here is the code in ContainerController:
- (void)viewDidLoad
{
[super viewDidLoad];
self.cont1 = [[FirstController alloc]initWithNibName:#"FirstView" bundle:nil];
self.cont2 = [[SecondController alloc]initWithNibName:#"SecondController" bundle:nil];
[self addChildViewController:self.cont1];
self.currentController = self.cont1;
[self.view addSubview:self.cont1.view];
}
-(void)switchToFirst {
if (self.currentController != self.cont1) {
[self addChildViewController:self.cont1];
[self moveToNewController:self.cont1];
}
}
-(void)switchToSecond {
if (self.currentController != self.cont2) {
[self addChildViewController:self.cont2];
[self moveToNewController:self.cont2];
}
}
-(void)moveToNewController:(id) newController {
[self.currentController willMoveToParentViewController:nil];
[self transitionFromViewController:self.currentController toViewController:newController duration:.6 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{}
completion:^(BOOL finished) {
[self.currentController removeFromParentViewController];
[newController didMoveToParentViewController:self];
self.currentController = newController;
}];
}
The only code I have in ViewController are the IBActions for the 2 buttons that switch the views. Those methods just call methods in the container controller:
-(IBAction)chooseFirstController:(id)sender {
[self.childViewControllers.lastObject switchToFirst];
}
-(IBAction)chooseSecondController:(id)sender {
[self.childViewControllers.lastObject switchToSecond];
}

What you are trying to do in your code is creating a class that is a subclass of multiple other classes, which is not possible. If you really want to do this, check out this question: Inherit from two classes
If you are trying to create multiple instances:
CoreDataTableViewController and NRGridViewController are just classes, which you will have to instantiate to get an actual object.
You can instantiate e.g. an NRGridViewController using
NRGridViewController *controller=[[NRGridViewController alloc] init];
I hope this answers your question, it is a bit difficult to understand your question.

Instead of taking tableViewController, take normal TableView (drag and drop from the storyboard to the particular position on the view).
when the button 1 is pressed Make the Table View hidden in the buttons action method. and initialize the grid view / or set grid view hidden to NO. (all views have the property of hidden in ios)
when you press on the 2nd and 3rd button set the grid view hidden and set tableview hidden equal to NO. and fetch the coredata and store it in array or dictionary or you can reload the tableview.
(Initially, before pressing the button 2 & 3 , the table view has no values. so you can set a bool property that when you press the button 2 or 3 set the bool and use the bool to reload your tabe view )
if you did not get my explanation ping me back.

Related

UIPageViewController within NavigationController

I've read every tutorial I've found about UIPageViewController, but they show just basics, I'd like to create something like new twitter app has:
UIPageViewController is embedded into Navigation controller, title of navigation bar is based on current page and those page dots are there as well, user can tap on item on current page(item from table view/collection view) to see detail.
I was able to come up with something similar, each page had collection view, and showing detail of some item was reflected in navigation bar, there was correct title and "<" button, but I wasn't able to change title based on currently shown page
Please, could you describe me how to do this in few steps/basic structure of controllers?
Don't know if you are still working on this but here goes anyway. To set up a UIPageViewController you might use the tutorial and two questions below.
http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/
How to implement UIPageViewController that utilizes multiple ViewControllers
How to add UIBarButtonItem to NavigationBar while using UIPageViewController
The last link pertains specifically to setting the contents of the navigationBar depending on what you are viewing.
The key is to create a UINavigationItem Property in the .h file of your UIPageViewController content view controllers, meaning the ones/one that are displaying whatever it is you are displaying.
From my code in FirstViewController.h SecondViewController.h and ThirdViewController.h
#property (strong, nonatomic) UINavigationItem *navItem;
In the second and third links above you'll see a storyboard layout of a Master-Detail application (which uses a navigation controller). The UIPageViewControllerDataSource is the DetailViewController. The three pages associated with the pageViewController are my content view controllers.
In DetailViewController.m you have to instantiate the contentViewControllers somewhere. At that point you pass the DetailViewControllers navigationItem id to the content view controllers. Here is how I instantiate my content view controllers using the delegate methods of the UIPageViewController.
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSString * ident = viewController.restorationIdentifier;
NSUInteger index = [_vc indexOfObject:ident];
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
if (index == 0) {
return [self controllerAtIndex:index];
}else if (index == 1){
return [self secondControllerAtIndex:index];
}else if (index == 2){
return [self thirdControllerAtIndex:index];
}else{
return nil;
}
}
The delegate method calls the method below. It is almost directly from the tutorial link with just a few modifications.
-(FirstController *)controllerAtIndex:(NSUInteger)index
{
FirstController *fvc = [self.storyboard instantiateViewControllerWithIdentifier:#"FirstPageController"];
fvc.imageFile = self.pageImages[index];
fvc.titleText = self.pageTitles[index];
fvc.pageIndex = index;
fvc.navItem = self.navigationItem;
return fvc;
}
Notice that properties are passed into the view controller including self.navigationItem. Passing it in ensures you can make changes to the navigationBar items.
Then in the viewDidAppear method of your content view controller you can simply set the title on the navigation bar like this.
navItem.navigationItem.title = #"Whatever you want the title to be";
It is important to use viewDidAppear because viewDidLoad is not called every time the screen appears. I believe the UIPageViewController caches the page before and the page after whatever you are viewing which saves the system from having to load the page every time you navigate to it.
If you are using a single view controller for all you pages like the tutorial does you will have to use the index property to know what to set the title to.
Hope this helps!
I had a very similar setup and solved the problem.
My setup is that I have a UIPageViewController inside a UINavigationController because I wanted the navigation bar to be persistent while I swiped between each view controller. I wanted the title of the current UIViewController inside the UIPageViewController to become the title of the UINavigationController.
The way to do this is to implement the UIPageViewControllerDelegate method pageViewController didFinishAnimating which triggers after a change to a view controller is made from the UIPageViewController. You can probably see where this going: From here, set the navigationItem.title property of the UIViewPageController, which the UINavigationController uses to set it's own title, with that of the current view controller's title.
Example:
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
if(finished && completed)
{
NSString *titleOfIncomingViewController = [[pageViewController.viewControllers firstObject] title];
pageViewController.navigationItem.title = titleOfIncomingViewController;
}
}
NB: This delegate method triggers only off gesture-initiated scrolls.
Solution given by Mr. Micnguyen is the exact solution but the mentioned delegate method didFinishAnimating() is called when swipe action is done due to which initially title is not shown.
Hence to resolve that problem, we need to set its initial value in viewDidLoad() method of UIPageViewController class as mentioned below:
- (void)viewDidLoad(){
self.navigationitem.title = arrayname[0];
}
I had this question too, but ended up doing something different, because I'm using Swift, so I thought I'd share here.
I ended up embedding a UIPageViewController in a Container View in my Navigation Controller. On a page swipe, I used pageViewController(_:didFinishAnimating:previousViewControllers:transitionCompleted:), with my PageViewController as the UIPageViewDelegate. From there I created a protocol that I used to send data about the VC displayed to the parent VC, and change the title using self.title = "My Title".
I didn't make the parent VC the UIPageViewDelegate because I found it to be easier to access the displayed VC from the PageViewController than from the parent VC as let childVC = pageViewController.viewControllers![0] as! DetailViewController.

how to display various view controllers (each having its respective navigation controller) using storyboard ID

I'm working on my first app. Here's what I want to accomplish:
There will be a menu with several different options. For simplicity, assume this is comprised of UIButtons with IBAction outlets and the functionality exists to pull up the menu at any time.
Each menu button, when pressed, should display a different navigation controller's content. If the user brings up the menu and makes a different selection, the navigation controller in which he is currently operating should not be affected; the newly selected navigation chain is displayed on top of the old, and through the menu, the user can go back to the view where he left off on the previous navigation chain at any time.
visual illustration (click for higher resolution):
Please note that there are 3 different navigation controllers/chains. The root view controller (which is also the menu in this simplified version) is not part of any of them. It will not suffice to instantiate one of the navigation chains anew when it has been previously instantiated, and here's why: if the user was on screen 3 of option 2 and then selects option 1 from the menu and then selects option 2 (again) from the menu, he should be looking at screen 3 of option 2--right where he left off; the view controller he was viewing when he previously left the navigation chain should be brought back to the top.
I can make a button instantiate and present a view controller from the storyboard if there is NOT a navigation controller:
- (IBAction)buttonPressed:(id)sender {
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"View 2"];
[self presentViewController:controller animated:YES completion:nil];
}
However, I can't figure out how to make those two methods work with a navigation controller involved. Moreover, I'm not sure those two methods are the right choice, because I won't always want to instantiate a new view controller: when a menu button is pressed, a check should be performed to see if the view (navigation?) controller with the corresponding identifier has already been instantiated. If so, it should simply be made the top view controller.
In summary, here are my questions:
1) How should I instantiate and display a view controller that is embedded in a navigation controller, preferably using a storyboard ID? Do you use the storyboard ID of the navigation controller or of the view controller?
2) How should I check whether an instance already exists? Again, should I check for an extant navigation controller or for a view controller, and what's the best method to do so?
3) If the selected navigation chain has already been instantiated and is in the stack of view controllers somewhere, what is the best method for bringing it to the top?
Thank you!!
side note -- it would be nice to know how to paste code snippets with indentation and color formatting preserved :)
As Rob has suggested, a tab bar controller would make a good organising principle for your design.
Add a UITabBarController to your storyboard, give it a storyboard iD. Assign each of your three sets of viewControllers ( with their respective navController) to a tab item in the tabBarController.
UITabBarController
|--> UINavigationController --> VC1 ---> VC2 -->
|--> UINavigationController --> VC1 ---> VC2 -->
|--> UINavigationController --> VC1 ---> VC2 -->
In you app delegate make a strong property to hold your tab bar controller's pointer. As the tab bar controller keeps pointers to all of it's tab items, this will take care of state for each of your sets of viewControllers. You won't have to keep separate pointers for any of them, and you can get references to them via the tabBarController's viewControllers property.
#property (strong, nonatomic) UITabBarController* tabVC;
Initialise it on startup
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard storyBoard =
[UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
self.tabVC = [storyBoard instantiateViewControllerWithIdentifier:#"tabVC"];
//hide the tab bar
for (UINavigationController* navController in self.tabVC.viewControllers)
[navController.viewControllers[0] setHidesBottomBarWhenPushed:YES];
return YES;
}
An alternative way to hide the tab bar is to check the "Hides bottom bar on push" box in the Attributes Inspector for each of the (initial) viewControllers. You don't have to do this for subsequent viewControllers, just the first one that will be seen in that tab item.
Then when you need to navigate to one of your navController groups…
- (IBAction)openTab:(UIButton*)sender {
AppDelegate* appDelegate =
(AppDelegate*)[[UIApplication sharedApplication] delegate];
if ([sender.titleLabel.text isEqualToString: #"Option 1"]) {
appDelegate.tabVC.selectedIndex = 0;
}else if ([sender.titleLabel.text isEqualToString: #"Option 2"]){
appDelegate.tabVC.selectedIndex = 1;
}else if ([sender.titleLabel.text isEqualToString: #"Option 3"]){
appDelegate.tabVC.selectedIndex = 2;
}
[self presentViewController:appDelegate.tabVC
animated:YES completion:nil];
}
(this example uses presentViewController, your app design may navigate this in other ways…)
update
If you want to do this without a tab bar controller, you can instantiate an array holding pointers to each of your nav controllers instead:
UINavigationController* ncA =
[storyboard instantiateViewControllerWithIdentifier:#"NCA"];
UINavigationController* ncB =
[storyboard instantiateViewControllerWithIdentifier:#"NCB"];
UINavigationController* ncC =
[storyboard instantiateViewControllerWithIdentifier:#"NCC"];
self.ncArray = #[ncA,ncB,ncC];
Which has the benefit of not having a tab bar to hide…
Then your selection looks like…
- (IBAction)openNav:(UIButton*)sender {
AppDelegate* appDelegate =
(AppDelegate*)[[UIApplication sharedApplication] delegate];
int idx = 0;
if ([sender.titleLabel.text isEqualToString: #"option 1"]) {
idx = 0;
}else if ([sender.titleLabel.text isEqualToString: #"option 2"]){
idx = 1;
}else if ([sender.titleLabel.text isEqualToString: #"option 3"]){
idx = 2;
}
[self presentViewController:appDelegate.ncArray[idx]
animated:YES completion:nil];
}
1 / You can instantiate a viewController in your viewDidLoad method of your main viewController, so it will be instantiate 1 time only.
Now if you want display your controller, you would better push it :
- (IBAction)buttonPressed:(id)sender {
// Declare your controller in your .h file and do :
controller = [self.storyboard instantiateViewControllerWithIdentifier:#"View 2"];
// Note you can move this line in the viewDidLoad method to be called only 1 time
// Then do not use :
// [self presentViewController:controller animated:YES completion:nil];
// Better to use :
[self.navigationController pushViewController:controller animated:YES];
}
2 / I'm not sure, but if you want to check if an instance already exist just check :
if (controller) {
// Some stuff here
} // I think this checks if controller is initiated.
3 / I know it's not a good advice but I would tell you to not worry about checking if your controller already exist, because I think it's easier to access your viewController by using the 2 lines again :
controller = [self.storyboard instantiateViewControllerWithIdentifier:#"View 2"];
[self.navigationController pushViewController:controller animated:YES];
4 / I'm not sure if colors can be used here because of a specific style sheets.
I'm not sure to really have the good answer to your question but I hope this will help you.

Custom button bar with custom back navigation button

Reusable button bars? gets me part of the way here, but now I'm having trouble with the "back button" requirements.
I need a layout solution that:
will work on iOS 5.0 and 6.0
has a custom view at the top with several buttons; this view should be reusable across every screen (scene), as opposed to duplicating the buttons manually in Interface Builder for each scene.
has a custom "back" button in that top custom view. With the design I have to implement, I cannot just use the default navigation bar
works well with the UINavigationController; when the user taps the "back" button, the main view controller (with the button bar) should stay, but the child view controller representing the actual scene content should go back to the previous scene.
The problem currently is that the "back" button won't change the child controller--it changes the parent controller, returning to the previous scene before the scene with the button bars. I've tried this several different ways. I'm not sure if I'm not doing it right, or if it can't be done.
One possibility is to implement my own "back" functionality, keeping a stack of child view controllers and manually changing them when the user taps "back." This is awkward, however, and poor design compared to using UINavigationController.
Perhaps I am going the wrong way with this. I can't accept duplicating the button bar across every single scene in Interface Builder... but perhaps I should create it programmatically, and then I can easily call that code from each and every scene. Then I would have "normal" view controllers, and using UINavigationController would be easier. But before I go that route and completely scrap what I have so far, I wanted to see if there was another way.
Here's an overview of some parts of my solution:
I created a ButtonBarController, laying out the Storyboard with a UIView for the buttons I wanted, and a UIView for the content pane. I also layered a button with the app logo (to go to the app's main screen) on top of a back button.
Then I created a controller for each of those other screens. In those subscreens/child view controllers, I would first add a UIView at the correct size to fit in my content pane, and then would add all the other controls I wanted. I had all of those child view controllers inherit from another controller, which took care of a few common tasks--such as procuring a reference to the button bar controller, and code to help resize the views for 3.5" versus 4" screens.
I created a changeToControllerWithIndex method; I call this when the app loads, when the user clicks one of the buttons in the main button bar to change scenes, or when anything happens in a scene requiring another scene change. I overload this method to provide two additional pieces of information: providing an NSDictionary with any extra information the child view controller needs, and to tell it whether this is a top-level scene, or whether we need a back button.
(Note: it's important to set the Storyboard ID for those child view controllers in the Identity Inspector. I kept accidentally setting the Title in the Attribute Inspector instead)
- (void)changeToControllerWithIndex:(NSInteger)index {
[self changeToControllerWithIndex:index withPayload:nil isRootView:YES];
}
// This is the method that will change the active view controller and the view that is shown
- (void)changeToControllerWithIndex:(NSInteger)index withPayload:(id)payload isRootView:(BOOL)isRootView
{
if (YES) {
self.index = index;
// The code below will properly remove the the child view controller that is
// currently being shown to the user and insert the new child view controller.
UIViewController *vc = [self setupViewControllerForIndex:index withPayload:payload];
if (isRootView) {
NSLog(#"putting navigation controller in");
childNavigationController = [[UINavigationController alloc] initWithRootViewController:vc];
[childNavigationController setNavigationBarHidden:YES];
[self addChildViewController:childNavigationController];
[childNavigationController didMoveToParentViewController:self];
if (self.currentViewController){
[self.currentViewController willMoveToParentViewController:nil];
[self transitionFromViewController:self.currentViewController toViewController:childNavigationController duration:0 options:UIViewAnimationOptionTransitionNone animations:^{
[self.currentViewController.view removeFromSuperview];
} completion:^(BOOL finished) {
[self.currentViewController removeFromParentViewController];
self.currentViewController = childNavigationController;
}];
} else {
[self.currentView addSubview:childNavigationController.view];
self.currentViewController = childNavigationController;
}
[self.currentView addSubview:childNavigationController.view];
//We are at the root of the navigation path, so no back button for us
[homeButton setHidden:NO];
[backButton setHidden:YES];
} else {
//Not a root view -- we're in navigation and want a back button
[childNavigationController pushViewController:vc animated:NO];
[homeButton setHidden:YES];
[backButton setHidden:NO];
}
}
}
Then I have an overloaded method to set up each individual view controller... some require a little more preparation than others.
- (UIViewController *)setupViewControllerForIndex:(NSInteger)index {
return [self setupViewControllerForIndex:index withPayload:nil];
}
// This is where you instantiate each child controller and setup anything you need on them, like delegates and public properties.
- (UIViewController *)setupViewControllerForIndex:(NSInteger)index withPayload:(id)payload {
UIViewController *vc = nil;
if (index == CONTROLLER_HOME){
vc = [self.storyboard instantiateViewControllerWithIdentifier:#"Home"];
} else if (index == CONTROLLER_CATEGORIES){
SAVECategoryViewController *child = [self.storyboard instantiateViewControllerWithIdentifier:#"Categories"];
if (payload) {
child.currentCategory = [(NSNumber *) [(NSDictionary *)payload objectForKey:ATTRIBUTE_CAT_ID] integerValue];
} else {
child.currentCategory = CATEGORY_ALL;
}
vc = child;
} //etc for all the other controllers...
payload = nil;
return vc;
}
I mentioned my difficulty with managing the "back" navigation. The above code ensures the navigation controllers maintain a proper "back" history, starting fresh whenever we use one of the button bar buttons to change screens. When we do use buttons inside a child controller to navigate from scene to scene, this is how we can go back:
- (IBAction)backButtonPressed:(id)sender {
[childNavigationController popViewControllerAnimated:YES];
if ([[childNavigationController viewControllers] count] <= 1) {
//Root view
[homeButton setHidden:NO];
[backButton setHidden:YES];
}
}
I think you need to implement at least one custom container view controller - the root view controller. That would be the one to host the custom button bar. Below the button bar you would add a UINavigationController the manage your other VCs. Look at this for starters:
#implementation RootVC
//...
- (void)viewDidLoad
{
self.navVC = [[UINavigationController alloc] initWithRootViewController:someOtherVC];
self.navVC.navigationBarHidden = YES;
self.navVC.view.frame = ...;
[self addChildViewController:self.navVC];
[self.view addSubview:self.navVC.view];
[self.navVC didMoveToParentViewController:self];
}
- (void)backButtonTouched:(UIButton *)button
{
[self.navVC popViewControllerAnimated:YES];
}

How to access the toolbar in a container view controller from its children?

I have the following view controller structure in my app:
A container view controller with a UIToolBar (which is not a navigation bar) has a UIPageViewController embedded and this UIPageViewController presents additional child view controllers:
container view controller (toolBar) -> PageViewController -> ViewController 1,
ViewController 2
I would like to add and remove buttons (BarButtonItems) to and from the toolbar on the container view controller depending on the child view controllers 1 and 2 presented.
How would you recommend that the child view controllers 1 and 2
access the toolbar in the container view controller to add and
remove buttons?
It seems that the toolbarItems property in the container view
controller is always 0 even though there are buttons in it. Any
ideas on why this could be? Is the toolbarItems property <> 0
only for navigation bars?
Edit
Based on the suggestion from user DBD I have added the following methods to the view controller CompanyViewController which has the toolbar and is the base class for my view controllers in a split views detail window (all my detail view controller inherit from CompanyViewController). One of these detail view controllers is used as a content view controller with a page view controller and the child view controllers described above.
CompanyViewController:
- (void)addToolBarItems:(NSArray *)buttonArray
{
NSMutableArray *items = [[self.toolbar items] mutableCopy];
[buttonArray enumerateObjectsUsingBlock:^(UIBarButtonItem *barButtonItem, NSUInteger idx, BOOL *stop) {
if (! [items containsObject:barButtonItem] ) [items insertObject:barButtonItem atIndex:0];
}];
[self.toolbar setItems:items animated:NO];
}
- (void)removeToolBarItems:(NSArray *)buttonArray;
{
NSMutableArray *items = [[self.toolbar items] mutableCopy];
[buttonArray enumerateObjectsUsingBlock:^(UIBarButtonItem *barButtonItem, NSUInteger idx, BOOL *stop) {
if ( [items containsObject:barButtonItem] ) [items removeObjectAtIndex:idx];
}];
[self.toolbar setItems:items animated:NO];
}
This is how I try to access the CompanyViewController from my child controllers:
- (CompanyViewController*)parentViewControllerWithToolbar
{
UIViewController *parentPageViewController = self.parentViewController;
CompanyViewController *parentContentViewController = (CompanyViewController*)parentPageViewController.parentViewController;
return (CompanyViewController*)parentContentViewController;
}
However, when trying to call the addToolBarItems method from the child view controller I can't get the method in Xcodes's autocomplete: It seems that I have no access to this method even though I imported #import "CompanyViewController.h".
Any suggestions on what I might be missing here?
I would suggest not accessing the toolbar directly. Instead, I'd suggest the container class having public methods like
- (void)addToolBarItem:(UIBarButtonItem *)button atIndex:(int)index;
- (void)removeToolBarItemAtIndex:(int)index;
Then all your child has to do is get the parent, possibly do a type cast and call the method.
Encapsulating your UI changes like this remove the need for potentially duplicate code in your child classes to modify the toolbar, protect much of your code from possible API changes by Apple and allow you to easily decide to swap out the tool bar to something like a custom control in the future without causing ripple code change effects.
EDIT:
I thought you were using a container view controller, not a UISplitViewController. I'm going to re-state my understanding so you can tell me if I got it wrong.
You have a UISplitViewController displaying a "master" and "detail" views. You want the detail view to call back to the master and request a toolbar change.
In detail view controller, you want the master, but calling "parent" just gives you the UISplitViewController. So you have to access the split view controller and get the master view controller from there.
MasterViewController *foo = [self.splitViewController.viewControllers objectAtIndex:0];
[foo removeToolBarItems:bar];
Which says, go get the UISplitViewController which I belong to (same as calling parent), then access the array of view controllers it holds. Take the first item in the array and assign as your master view controller. From the docs on the UISplitViewController
viewControllers
The array of view controllers managed by the receiver.
#property(nonatomic, copy) NSArray *viewControllers
Discussion
The
array in this property must contain exactly two view controllers. The
view controllers are presented left-to-right in the split view
interface when it is in a landscape orientation. Thus, the view
controller at index 0 is displayed on the left side and the view
controller at index 1 is displayed on the right side of the interface

How to load a view controller using a segmentControl value change event?

I have three views each represented by a View controller named firstVC, secondVC and thirdVC. In the firstView (firstVC) I have a segmented control with three options first,second and third. When I click on the second segment control I want to load the corresponding view controller which in this case would be secondVC. I am new to View Controllers but I did try various options. I created an outlet and also a value changed event. I event tried pushing a view controller when the value changes but it pulls a blank page as opposed to secondVC.
Please see below for the code.
- (IBAction)chainAction:(id)sender {
UINavigationController *navcon = self.navigationController;
if (chainSegControl.selectedSegmentIndex == 1) {
secondVC *atSecondVCChain = [[secondVC alloc] init];
[navcon pushViewController:atSecondVCChain animated:YES];
}
}
Any help would be greatly appreciated. Thank You.
P.S I am using Xcode 4.2
Instead of using alloc to create a controller, define a named segue in your storyboard (if you don't already have one) that describes a push from firstVC to secondVC and then use the performSegueWithIdentifier:sender: method instead of pushViewController:.