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

timbojill

macrumors member
Original poster
May 21, 2011
31
0
How do you turn a Tab Bar Application into a View-Based Application. I have a Tab Bar Application already submitted into the app. View my blog and look at the learning Center. Instead of Tabs I want one view as my main view and that from the main view have buttons that switch to and from other xib files.
 

timbojill

macrumors member
Original poster
May 21, 2011
31
0
I ignored the Tab Bar and added buttons to the main view. But what is the code to have the xib files connected.
 

nickculbertson

macrumors regular
Nov 19, 2010
226
0
Nashville, TN
Code:
-(IBAction)changeSecondView{
SecondView *views = [[SecondView alloc] initWithNibName:Nil bundle:nil];
	[self presentModalViewController:views animated:NO];
}

You will also want to create a SecondView .h and .m file by right clicking your Class folder and selecting Add > New File. Add a UIViewController subclass (uncheck the add xib if you already have one). click Next. Set the file name to SecondView.m and make sure the Also create "SecondView.h" box is checked. Then at the top of your FirstViewController.m add
Code:
#import "SecondView.h"

Nick
 

timbojill

macrumors member
Original poster
May 21, 2011
31
0
Code:
-(IBAction)changeSecondView{
SecondView *views = [[SecondView alloc] initWithNibName:Nil bundle:nil];
	[self presentModalViewController:views animated:NO];
}

You will also want to create a SecondView .h and .m file by right clicking your Class folder and selecting Add > New File. Add a UIViewController subclass (uncheck the add xib if you already have one). click Next. Set the file name to SecondView.m and make sure the Also create "SecondView.h" box is checked. Then at the top of your FirstViewController.m add
Code:
#import "SecondView.h"

Nick

I tried to use a .h and .m file I already had. The name is 2nd.h and 2nd.m.

So should it be:
Code:
2nd *views = [[2nd alloc] initWithNibName:Nil bundle:nil];
	[self presentModalViewController:views animated:NO];

?
 
Last edited by a moderator:

nickculbertson

macrumors regular
Nov 19, 2010
226
0
Nashville, TN
You will be loading the xib file this way. So if your xib name is "2nd" then your code is correct. the code written in your 2nd.h and .m can be linked to your 2nd.xib (or any xib for that matter) by opening interface builder -> select your files owner -> select the last tab (i) on the identity inspector window -> change class to 2nd.

Nick
 

nickculbertson

macrumors regular
Nov 19, 2010
226
0
Nashville, TN
The application looks pretty messy. I believe the reason it is crashing is because you are trying to change the view from a UIView, not a UIViewController. I'd recommend starting fresh with a new view based app. It shouldn't take long since all you have now are a few buttons linked to functions you are not using. In the view based app add the .h and .m files like I said but check the box to include the xib.
Good Luck,
Nick
 

timbojill

macrumors member
Original poster
May 21, 2011
31
0
The application looks pretty messy. I believe the reason it is crashing is because you are trying to change the view from a UIView, not a UIViewController. I'd recommend starting fresh with a new view based app. It shouldn't take long since all you have now are a few buttons linked to functions you are not using. In the view based app add the .h and .m files like I said but check the box to include the xib.
Good Luck,
Nick

I already started from the beginning. I took an example of a view app and try to modify it. If you ran the program the first button works. I just need to find a way to add the other buttons to link to the other .h files and xib files I have.

EDIT:

In the example I used he added all the xib's to the main xib. I want to uses other xibs I imported.

EDIT 2:

http://www.mediafire.com/?swbm2ksyefdzzm3 nick I hope you still around. I started from the beginning with a new view-based project. In the LC4Viewcontroller.m I get an error in the IBAction that calls the first views from the main view.

Code:
- (IBAction)view2 {
    [self addSubview:Letter];
}

The error is expected expression before letter. Can anyone help me out.

EDIT 3:

Can someone add a third view called view3 and connect it for me. When I did it it said view3 undecleared. I don't know why I am having so much trouble.

http://www.esnips.com/doc/66bb2e0c-173a-4ce7-8685-4969b13db895/new
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.