changing the view in MainWindow.xib

Discussion in 'iOS Programming' started by aaronbastian, Sep 23, 2010.

  1. aaronbastian macrumors newbie

    Joined:
    Sep 23, 2010
    #1
    Hi,

    I am a newbie to the iPhone SDK, but have been teaching myself syntax through youtube tutorials.

    Anyway, I am having trouble with a mutiview Window based application, in the simplest loading a view into MainWindow. When I Build and Run, I get no syntax errors, but it loads iPhone sim, and then backs out of the app completely.

    I know that there is a simple fix to this that I am not seeing, and I hoped that with the years of experience on this forum that SOMEONE could help a newbie with a simple fix!

    My viewDidLoad is coded as follows:
    Code:
    -(void) viewDidLoad{
    	homeClass *home = [[homeClass alloc]initWithNibName:@"home" bundle:nil];
    	self.HomeClass = home;
    	
    	[self.view insertSubview:home.view atIndex:0];
    	[home release];
    	[super viewDidLoad];
    }
    
    any help?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    And nothing appears in the Console window? If something abnormal does appear, what does it say? If nothing abnormal, you should probably put in a breakpoint and start stepping through the code until you get to the line it crashes on. Then start to figure out why that line is bad.

    Also, although homeClass is a valid class name, the typical convention is to name classes starting with an upper-case to differentiate them from variables, which typically start with a lower-case.
     
  3. aaronbastian thread starter macrumors newbie

    Joined:
    Sep 23, 2010
    #3
    the window appears blank for about a second before it backs out. could it be something that i didn't tie in the interface builder?

    thanks for the help!!
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Could be. What have you created in the IB?
     
  5. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #5
    What errors are you getting on the console? Have you tried running with build and debug to see where its crashing?
     
  6. aaronbastian thread starter macrumors newbie

    Joined:
    Sep 23, 2010
    #6
    It's giving me no errors, or even warnings. I have currently in the MainWindow.xib, a view controller, and a view. The view controller is tied to the class (switchClass) that has the viewDidLoad method in it. The viewDidLoad method calls home.xib, which has nothing but 6 images and 2 buttons that are supposed to change views again.

    I'm stuck, and I'm sure it's a simple fix. Thanks again!
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    It's hard to debug descriptions. Please provide some code. Also, if you need to, screencaps of your IB work and connections.
     
  8. aaronbastian thread starter macrumors newbie

    Joined:
    Sep 23, 2010
    #8
    My entire switchClass.m:

    Code:
    
    #import "switchClass.h"
    #import "chetProducts.h"
    #import "lolaProducts.h"
    #import "chetSearch.h"
    #import "lolaSearch.h"
    #import "homeClass.h"
    
    
    @implementation switchClass
    @synthesize ChetProducts;
    @synthesize LolaProducts;
    @synthesize ChetSearch;
    @synthesize LolaSearch;
    @synthesize HomeClass;
    
    -(void) viewDidLoad{
    	homeClass *home = [[homeClass alloc]initWithNibName:@"home" bundle:nil];
    	self.HomeClass = home;
    	
    	[self.view insertSubview:home.view atIndex:0];
    	[home release];
    	[super viewDidLoad];
    }
    
    -(IBAction) lolaButton: (id)sender{
    	lolaProducts *lola = [[lolaProducts alloc]initWithNibName:@"lolaProducts" bundle:nil];
    	self.LolaProducts = lola;
    	
    	[self.view insertSubview:lola.view atIndex:0];
    	[lola release];
    	[super viewDidLoad];
    }
    
    -(IBAction) chetButton: (id)sender{
    	chetProducts *chet = [[chetProducts alloc]initWithNibName:@"chetProducts" bundle:nil];
    	self.ChetProducts = chet;
    
    	[self.view insertSubview:chet.view atIndex:0];
    	[chet release];
    	[super viewDidLoad];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        
    }
    
    - (void)viewDidUnload {
        [super viewDidUnload];
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    
    @end
    
    Please correct me if I am wrong; I have a different class for each xib file, a different class for each screen developed thus far.

    my MainWindow.xib looks like this:
    http://www.facebook.com/photo.php?pid=5660154&l=4b1f28fbed&id=506231875


    For a better look at the connections:
    http://www.facebook.com/photo.php?pid=5660245&l=ec3789f48b&id=506231875

    my home.xib looks like this:
    http://www.facebook.com/photo.php?pid=5660155&l=3f89ec8878&id=506231875
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Hmm, so as far as I can tell, you've shown us how you are trying to load the "home" view into switchClass. But you haven't shown us how you are adding switchClass's view into MainWindow's.
     
  10. aaronbastian thread starter macrumors newbie

    Joined:
    Sep 23, 2010
    #10
    I have loaded into the View Controller into MainWindow.xib, and then set its class as switchClass. This is all that I have done in IB with the MainWindow. What did I miss?
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    I think you're missing the part where you actually have MainWindow display the view for switchClass. I'm curious: where have you learned this particular technique? Perhaps now would be a good time to step back from the real coding and learn some more about View Programming for iOS.
     

Share This Page