Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fzaman

macrumors newbie
Original poster
Jun 16, 2011
4
0
I'm a newbie and trying to build a multiview app and can't really get my head straight on what approach is the best. I'm interested to know how to switch from one controller to another without clicking a Tabbar, Navigationbar or a Button. Basically there'll be a puzzle on first view controller's view which when 'solved' will switch to second view controller and so on.
Any help is appreciated.
 
The code you would run inside your IBAction for a button click is the same code you can run based on any other trigger, such as when the first puzzle is solved.
 
In many cases, if you don't want the appearance of a navbar you can still use a navigation controller, but use a hidden navbar. Then you can use the navigation controller to push/pop view controllers.
 
There are so many options if u wouldve taken a look around.

A nav app without navbar, so you have the options laying around for you, for switching, and popping etc. You could do a Utility app, that does 1 thing, and flips around the view to the back.
You could also do a normal window app, just add a modalviewcontroller with "Solved" on it.

Alot of things to try out imo.

Gl.
 
The code you would run inside your IBAction for a button click is the same code you can run based on any other trigger, such as when the first puzzle is solved.


Dejo,
I followed an example of multiple views from here

http://stackoverflow.com/questions/...-how-to-switch-between-views-programmatically

And changed the - (IBAction)switchViews method with (void) method and kept the code same. Then on blue view controller's view class I created an instance of SwitchViewController and call out switchViews method when the puzzle is solved but somehow the blue view controllers view doesn't get removed. Am I doing something wrong here ?
 
I think it is best to check out a iPhone book which has everything you are asking for right in there, with source, or by following the book. That will improve your skills way better then this ping ponging of answers.. What did you try to delete the view, how did you do it, what doesn't it do. How did you check if it didn't work.
We don't know what u did/tried, so can't give decent answers. Don't really know how to put it else.
 
Dejo,
I followed an example of multiple views from here

http://stackoverflow.com/questions/...-how-to-switch-between-views-programmatically

And changed the - (IBAction)switchViews method with (void) method and kept the code same. Then on blue view controller's view class I created an instance of SwitchViewController and call out switchViews method when the puzzle is solved but somehow the blue view controllers view doesn't get removed. Am I doing something wrong here ?
It's really hard to know if you're doing something wrong because it is rather difficult to debug a description of your code. Post your code and we can better assess what the issue might be.
 
The code you would run inside your IBAction for a button click is the same code you can run based on any other trigger, such as when the first puzzle is solved.

It's really hard to know if you're doing something wrong because it is rather difficult to debug a description of your code. Post your code and we can better assess what the issue might be.

dejo,
Is it possible to send you the code via email ? its impossible to post entire everything over here. Please shoot me an email at fzaman2@gmail.com and i'll send you the code. Thank you very much for cooperating.
 
dejo,
Is it possible to send you the code via email ? its impossible to post entire everything over here. Please shoot me an email at fzaman2@gmail.com and i'll send you the code. Thank you very much for cooperating.
I think it would be better to post the code here and have multiple eyes looking at it vs. emailing it to me and only having me look at it, when I get a chance.

And you shouldn't need to post your entire code here. What you are asking for should be simple enough that a few methods (and perhaps some accompanying explanation and/or .h file) should suffice.

I would suggest posting your switchViews method as well as the code for the method that calls it.
 
I think it would be better to post the code here and have multiple eyes looking at it vs. emailing it to me and only having me look at it, when I get a chance.

And you shouldn't need to post your entire code here. What you are asking for should be simple enough that a few methods (and perhaps some accompanying explanation and/or .h file) should suffice.

I would suggest posting your switchViews method as well as the code for the method that calls it.

Here is the viewDidLoad and switchView method of root view controller class "Switch View Controller"


Code:
- (void)viewDidLoad
{

    BlueViewController *blueController = [[BlueViewController alloc] initWithNibName:@"BlueViewController" bundle:nil];
    self.blueViewController = blueController;
    [blueController release];
    [blueViewController viewWillAppear:YES];
    [self.view addSubview:blueViewController.view];
    [blueViewController viewDidAppear:YES];
    [super viewDidLoad];
    
}

-(void) switchView
{
   
    if (self.yellowViewController.view.superview == nil)
    {
        if (self.yellowViewController == nil)
        {
            
            YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowViewController" bundle:nil];
            self.yellowViewController =  yellowController;
            [yellowController release];
        }
        [blueViewController viewWillDisappear:YES];
        [blueViewController.view removeFromSuperview];
        
        [yellowViewController viewWillAppear:YES];
        [self.view addSubview:yellowViewController.view];
        [blueViewController viewDidDisappear:YES];
        [yellowViewController viewDidAppear:YES];
    }
    else if (self.blueViewController.view.superview == nil)
    {
        if (self.blueViewController == nil)
        {
            NSLog(@"self.blueviewcontroller = nil");
            BlueViewController *blueController = [[BlueViewController alloc] initWithNibName:@"BlueViewController" bundle:nil];
            self.blueViewController = blueController;
            [blueController release];
        }
        [yellowViewController viewWillDisappear:YES];
        [yellowViewController.view removeFromSuperview];
        [blueViewController viewWillAppear:YES];
        [self.view addSubview:blueViewController.view];
        [yellowViewController viewDidDisappear:YES];
        [blueViewController viewDidAppear:YES];
    }
    
}

And touchesMoved method inside "FirstView" class of "Blue View Controller" which creates instance of switch view controller and calls out switchViews

Code:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *t = [touches anyObject];
    CGPoint touchLocation = [t locationInView:self];
    CGRect squareRect = [square frame];
    
    if (CGRectContainsPoint(squareRect, touchLocation))
    {
        square.center = touchLocation;
        if (CGRectContainsPoint([destination frame], touchLocation))
        {
            square.center = destination.center;
            SwitchViewController *switchController = [[SwitchViewController alloc] initWithNibName:@"SwitchViewController" bundle:nil];
            self.switchViewController = switchController;
            [switchController release];
            [self.switchViewController switchView];
            
        }
    }
    
}

Let me know what you think of it.
Thanks
 
Last edited by a moderator:
And touchesMoved method inside "FirstView" class of "Blue View Controller"...
This sounds confusing to me. I get that touchesMoved is a method, but where does it reside? Do you have a FirstView class? Or does this method reside within BlueViewController.m? Perhaps elaborate on what you are trying to say with that statement.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.