Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-24-2010, 08:41 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 6
lindseyv is on a distinguished road
Default Using buttons, located on the same xib, to bring up different views

I am new to objective c development and I have searched for the last couple days on how to solve this problem. Essentially, I am trying to create a main menu for my application that contains three buttons that will load different views depending on the button the the user hits. All of the tutorials I have seen only show one button and every time I add the second, my program crashes. Below is the code that I have put together for two buttons

The second button is working correctly and the buttons are being connected the same way. I have even tried adding two view controllers to direct them.

In the main.h

@interface ViewViewController : UIViewController {


IBOutlet SecondViewController *secondViewController;
IBOutlet FourthViewController *fourthViewController;
}

- (IBAction)gotoSecondView;
- (IBAction)gotoFourthView;


In the main .m
- (IBAction)gotoSecondView{
[self presentModalViewController:secondViewController animated:YES];
}

- (IBAction)gotoFourthView{
[self presentModalViewController:fourthViewController animated:YES];
}

Thank you.
lindseyv is offline   Reply With Quote
Old 05-24-2010, 08:42 AM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 6
lindseyv is on a distinguished road
Default

I want to clarify, the second view is working correctly by itself, the program crashes when I try adding the new button/view.
lindseyv is offline   Reply With Quote
Old 05-24-2010, 09:31 AM   #3 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Hi,

you may want to try changing your methods to something like this:

Code:
- (IBAction)gotoSecondView{
secondViewController = [[SecondViewController alloc] initWithNibName: nil bundle: nil]; 
[self presentModalViewController:secondViewController animated:YES];
[secondViewController release];
}
Hope this helps.

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 05-24-2010, 12:05 PM   #4 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 223
mr tickle is on a distinguished road
Default

you should be dismissing the current modalviewcontroller

i dont think you can just say present first, now present the other one.

Quote:
Originally Posted by lindseyv View Post
I want to clarify, the second view is working correctly by itself, the program crashes when I try adding the new button/view.
mr tickle is offline   Reply With Quote
Old 05-26-2010, 10:59 AM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 6
lindseyv is on a distinguished road
Default

thank you for the advice but it fails... this program is driving me crazy. The new view I am trying to add is now orderview.


- (IBAction)gotoSecondView{
secondViewController = [[SecondViewController alloc] initWithNibName:nil bundle: nil];
[self presentModalViewController:secondViewController animated:YES];
[secondViewController release];
}

- (IBAction)gotoOrderViewV1{
[self presentModalViewController:addWorkOrderControllerV 1 animated:YES];
OrderControllerV1 = [[OrderControllerV1 alloc] initWithNibName:nil bundle:nil];
[OrderControllerV1 release];
}
lindseyv is offline   Reply With Quote
Old 05-26-2010, 11:10 AM   #6 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

What do you mean 'it fails'? The code you posted cannot work:

Code:
- (IBAction)gotoOrderViewV1{
[self presentModalViewController:addWorkOrderControllerV 1 animated:YES];
OrderControllerV1 = [[OrderControllerV1 alloc] initWithNibName:nil bundle:nil];
[OrderControllerV1 release];
}
The logic goes like this: Create a new view controller, present it, release it. You try to present it without having created it and your typing is messed up. Are addWorkOrderControllerV1 and OrderControllerV1 supposed to be the same? If yes, you have to use the same name. If not, you have to create addWorkOrderControllerV1 before you can do something with it.

Assuming they are the supposed to be the same, try

Code:
- (IBAction)gotoOrderViewV1{
OrderControllerV1 *orderCont= [[OrderControllerV1 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController: orderCont animated:YES];
[orderCont release];
}
Hope this helps.

Cheers,
Bob

P.S.: If it doesn't help, we need more information about what's actually going wrong. Even though we try real hard, we can't read your mind.
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 05-26-2010, 01:42 PM   #7 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 6
lindseyv is on a distinguished road
Default

they are not the same. the user can chose one of two buttons on the current view, one the buttone will bring up a new view,WorkOrderControllerV1, and the other button will bring up another view, OrderControllerV1.

Sorry I am very new to this and I am trying to understand. As I search the internet it seems that this question has been asked and unanswered many times.
lindseyv is offline   Reply With Quote
Old 05-26-2010, 01:56 PM   #8 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Okay, for what you want to do, you'll need two separate buttons (obviously) and two separate methods. (Well, not necessarily, but let's keep it simple.)

Use Interface Builder to create both buttons and then implement the following two methods in your .m file:

Code:
- (IBAction)gotoOrderViewV1{
OrderControllerV1 *orderCont= [[OrderControllerV1 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController: orderCont animated:YES];
[orderCont release];
}

- (IBAction)gotoOrderViewV1{
WorkOrderControllerV1 *workOrderCont= [[WorkOrderControllerV1 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController: workOrderCont animated:YES];
[workOrderCont release];
}
This, of course, assumes that you have actually created OrderControllerV1 and WorkOrderControllerV1 with its corresponding NIB files. Now you only need to connect the buttons with the IBActions (in Interface Builder).

Hope this helps.

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 05-26-2010, 02:25 PM   #9 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 6
lindseyv is on a distinguished road
Default

Thanks for the help. Yet again the first button works and the second fails.
lindseyv is offline   Reply With Quote
Old 05-26-2010, 03:05 PM   #10 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Yet again, what does "fails" mean? You need to be more specific.

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 05-26-2010, 03:09 PM   #11 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 6
lindseyv is on a distinguished road
Default

The second button will not load correctly. It have tried writing this about 10 different ways and the best I have gotten it is that the second button will only go load to the mainmenu.xib.
lindseyv is offline   Reply With Quote
Reply

Bookmarks

Tags
button, iphone, subview, view change

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 308
10 members and 298 guests
ajay123123, ashaman64, baja_yu, ChrisYates, guusleijsten, HemiMG, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,878
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:53 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0