-1

This is the code i have been using while i click the button there is no action occurs in my view controller.

 - (IBAction)controlleraction:(id)sender {

    ChildViewController *child=[[ChildViewController alloc]init];

   rootviewController *firstview= [[rootviewControllerone alloc]init];
    [self addChildViewController:child];
    child.view.frame = self.container.frame;//container is a container view (uiview)
    [self.container addSubview:child.view];
    [firstview removeFromParentViewController];
    [child didMoveToParentViewController:self];
         NSLog(@"working");


}

i have updated my code as per the suggestion and this code is not working for me .

enter image description here while i click the button the container view controller have to load in my container view.

Kishore kumar
  • 143
  • 1
  • 14
  • Please add the code you have tried. And specify what was the issue you faced in that. – Midhun MP Jul 24 '15 at 11:39
  • Go through some tutorial, this is so basic that you should learn it on the first tutorial. This is question-answer site, not tutorials.. Open eg raywenderlich site, they have great tutorials. You're not asking how to present different controller, you're asking for whole solution. Also it'd be good to reread the question before posting it, because it's hard to understand your language. – Nat Jul 24 '15 at 12:06
  • i tried and edited my code now i hope you friends help me to find out the problem. – Kishore kumar Jul 24 '15 at 13:36
  • @Kishorekumar: What is ContainerViewController ? Did you added any container view controller in your main view controller ? You are adding the view controller's view to self.view. Also what is the issue you are facing ? – Midhun MP Jul 24 '15 at 14:05
  • that container view is a normal view controller ,in my root view controller i have container ,if i click the button the container view controller have to load inside a container. – Kishore kumar Jul 24 '15 at 14:17
  • but when i click the button no action occurs – Kishore kumar Jul 24 '15 at 14:18
  • Please read this article [View Controller Containment](http://www.objc.io/issues/1-view-controllers/containment-view-controller/) – iamandrewluca Jul 24 '15 at 17:58
  • @Kishorekumar You want to load a new View Controller on button click. Right? – Radix Jul 25 '15 at 06:47
  • yes while i click the button the new view controller have to load in my container – Kishore kumar Jul 25 '15 at 06:50
  • I think you need to do some search before posting a question in StackOverflow. – Radix Jul 25 '15 at 07:14
  • @AtulKhanduri i think now you will understand my problem. – Kishore kumar Jul 25 '15 at 09:14
  • I have added an answer, check that. If you need still need any help then let me know. – Radix Jul 25 '15 at 10:08

1 Answers1

1

To load a new View Controller on Button Click do the following:

Connect your first Controller to second, push or modal segue, and give some name to the segue, under Attribute section, right side panel of the storyboard.

And then in your Implementation file, write the below code

- (IBAction)controlleraction:(id)sender
{
   [self performSegueWithIdentifier:@"SegueIdentifier" sender:nil];
}

This link must be helpful for you.

EDIT: To call the other two controllers on button click:

1) Remove the connection of button to the VC.

2) Connect all the three controllers (VC with Yellow, Purple and Black background) with first controller (VC having button)

3) Set ID to 3 different segues, Segue Identifier (under Attribute section, right side panel of the storyboard).

4) Then call different VC on button click programatically:

- (IBAction)controlleraction:(id)sender
{
   if (CONDITION FOR 1ST VC)
      [self performSegueWithIdentifier:@"SegueIdentifier1" sender:nil];
   else if (CONDITION FOR 2nd VC)
      [self performSegueWithIdentifier:@"SegueIdentifier2" sender:nil];
   else if (CONDITION FOR 3rd VC)
      [self performSegueWithIdentifier:@"SegueIdentifier3" sender:nil];
}
Community
  • 1
  • 1
Radix
  • 2,527
  • 1
  • 19
  • 43
  • my button action is happens in first view controller how i have to call the third view controller – Kishore kumar Jul 25 '15 at 10:36
  • then i have to load the viewcontroler into container – Kishore kumar Jul 25 '15 at 10:37
  • Okay so you want to call ViewController with purple and black background. Right? if so then I'll update my answer. – Radix Jul 25 '15 at 11:07
  • S bro correct I want to call that vc and then I have to load the vc to container view – Kishore kumar Jul 25 '15 at 11:09
  • @Kishorekumar if this answer has solved your question please consider [accepting it](http://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Radix Jul 25 '15 at 11:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84260/discussion-between-kishore-kumar-and-atul-khanduri). – Kishore kumar Jul 25 '15 at 12:01