PDA

View Full Version : How do you turn a Tab Bar Application into a View-Based Application...




timbojill
Jun 2, 2011, 04:00 PM
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.



nickculbertson
Jun 2, 2011, 10:12 PM
Just delete or ignore your tab bar button functions and create UIButtons to navigate your views.
Nick

timbojill
Jun 3, 2011, 07:39 AM
I ignored the Tab Bar and added buttons to the main view. But what is the code to have the xib files connected.

nickculbertson
Jun 3, 2011, 08:04 AM
-(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
#import "SecondView.h"

Nick

timbojill
Jun 3, 2011, 08:39 AM
-(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
#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:

2nd *views = [[2nd alloc] initWithNibName:Nil bundle:nil];
[self presentModalViewController:views animated:NO];



?

nickculbertson
Jun 3, 2011, 09:06 AM
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

timbojill
Jun 3, 2011, 09:16 AM
http://www.mediafire.com/?iby0z3obz9fj1ah. Can you take a look at my program and she what I am doing wrong.

nickculbertson
Jun 3, 2011, 09:52 AM
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
Jun 3, 2011, 10:32 AM
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.



- (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