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 07-29-2011, 11:18 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 27
AnthonysABAMF is on a distinguished road
Question [NAME relase]

Modal View Controller...


What does the [NAME relase] part of it do? Does it ... "pop" the previous view so you aren't creating 1,000+ stacks?


I circumvented my "back" issue by just linking each button with an MVC. However I am worried I would create a HUGE stack by doing this. However someone said in another thread if I [NAME release] at the end of each MVC it will save the memory.

I got too annoyed with the "back button" issue and just said screw it, that I knew another way to make it work. However, would this be safe to do? And would it get approved by Apple by doing it this way?

Anyone with any answers is appreciated!


Code:
-(IBAction)pushViewMap {
	MapViewController *map = [[MapViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:map animated:YES];
    [map release];
}

-(IBAction)pushViewAthletics {
	AthleticsViewController *athletics = [[AthleticsViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:athletics animated:YES];
    [athletics release];
}

-(IBAction)pushViewPortal {
	PortalViewController *portal = [[PortalViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:portal animated:YES];
    [portal release];
}

-(IBAction)pushViewPolice {
	PoliceViewController *police = [[PoliceViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:police animated:YES];
    [police release];
}

-(IBAction)pushViewCatalog {
	CatalogViewController *catalog = [[CatalogViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:catalog animated:YES];
    [catalog release];
}

-(IBAction)pushViewNews {
	NewsViewController *news = [[NewsViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:news animated:YES];
    [news release];
}	

-(IBAction)pushViewEvents {
	EventsViewController *events = [[EventsViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:events animated:YES];
    [events release];
}

-(IBAction)pushViewLibrary {
	LibraryViewController *library = [[LibraryViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:library animated:YES];
    [library release];
}

-(IBAction)pushViewRate {
	RateViewController *rate = [[RateViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:rate animated:YES];
    [rate release];
}

-(IBAction)pushViewBlackboard {
	BlackboardViewController *blackboard = [[BlackboardViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:blackboard animated:YES];
    [blackboard release];
}	

-(IBAction)pushViewUCF {
    iUCFViewController *ucf = [[iUCFViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:ucf animated:YES];
    [ucf release];
}
AnthonysABAMF is offline   Reply With Quote
Old 07-29-2011, 11:35 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

It does the exact same thing as for any other object. It lowers the retain count. Since you alloc/init a new object, you own it, so you must release it. Modal view controllers are disposed of by calling dismissModalViewController.
baja_yu is offline   Reply With Quote
Old 07-29-2011, 11:57 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 27
AnthonysABAMF is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
It does the exact same thing as for any other object. It lowers the retain count. Since you alloc/init a new object, you own it, so you must release it. Modal view controllers are disposed of by calling dismissModalViewController.
Alright. Where would I implement this code??

Would I replace it so it looked like this:

WHAT IT LOOKS LIKE
Code:
#import "PoliceViewController.h"
#import "PoliceWebViewController.h"
#import "iUCFViewController.h"


@implementation PoliceViewController

-(IBAction)pushViewPoliceWeb {
	PoliceWebViewController *policeweb = [[PoliceWebViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:policeweb animated:YES];
    [policeweb release];*********
}

-(IBAction)pushViewUCF {
    iUCFViewController *ucf = [[iUCFViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:ucf animated:YES];
    [ucf release];**********
}

WHAT IT WILL LOOK LIKE:
Code:
#import "PoliceViewController.h"
#import "PoliceWebViewController.h"
#import "iUCFViewController.h"


@implementation PoliceViewController

-(IBAction)pushViewPoliceWeb {
	PoliceWebViewController *policeweb = [[PoliceWebViewController alloc] initWithNibName:nil bundle:nil];
	[self presentModalViewController:policeweb animated:YES];
    [self dismissModalViewControllerAnimated:YES];********

}

-(IBAction)pushViewUCF {
    iUCFViewController *ucf = [[iUCFViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:ucf animated:YES];
    [self dismissModalViewControllerAnimated:YES];**********
}

Would that do what I am looking for?

Last edited by AnthonysABAMF; 07-30-2011 at 12:41 AM.
AnthonysABAMF is offline   Reply With Quote
Old 07-30-2011, 12:12 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 194
mavrik5150 is on a distinguished road
Default

On the ViewController that you are presenting if you have a Button or something that is supposed to dismiss that view and bring them back to the previous view then you would use [self dismissModalViewController].

For example in the first ViewController (PoliceWebViewController) you should have some action that would allow the person to return back to PoliceViewController and that's where you would use the dismissModalViewController.
mavrik5150 is offline   Reply With Quote
Old 07-30-2011, 12:29 AM   #5 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Your first code was ok. The dismiss should be called, as mavrik said, when you want to remove/dispose of/close the view that you presented with presentModalViewController.
baja_yu is offline   Reply With Quote
Old 07-30-2011, 12:30 AM   #6 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 27
AnthonysABAMF is on a distinguished road
Default

Quote:
Originally Posted by mavrik5150 View Post
On the ViewController that you are presenting if you have a Button or something that is supposed to dismiss that view and bring them back to the previous view then you would use [self dismissModalViewController].

For example in the first ViewController (PoliceWebViewController) you should have some action that would allow the person to return back to PoliceViewController and that's where you would use the dismissModalViewController.
I do. I created a button for it. Like a button on my home screen.

Home Screen:iUCFViewcontroller



The "Police Button" is tapped which brings up: PoliceViewController



They can tab the "Main" button the top to go back to the iUCFViewController
OR
The white "UCF Police Website" button is tapped which brings up: PoliceWebViewController


Then they can navigate through the webView OR go back to: PoliceViewController using the method provided.




again. this was done by duplicating the button setup from the iUCFViewController. So I am just creating a huge stack by doing this. I need to find out WHERE in my coding to put "[self dismissModalViewControllerAnimated:YES];" so I dont do that, but no one has been able to tell me WHERE, based on the code I provided above

the "before" and "after" code I did.

I replaced the [NAMEOFVIEW release]
with
[self dismissModalViewControllerAnimated:YES];

but no answers if thats where I SHOULD put it.

Last edited by AnthonysABAMF; 07-30-2011 at 12:34 AM.
AnthonysABAMF is offline   Reply With Quote
Old 07-30-2011, 12:57 AM   #7 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 194
mavrik5150 is on a distinguished road
Default

Well firstly you don't want to replace the [NAME release] statement, since you need that to release the memory that was retained when creating your object.

I did say where you should put it, I just didn't give you any code. Figured you would find that part yourself. Based on your screenshots you don't want the present and dismiss code in the same action, that does nothing. On each New View Controller you are calling (so looking at your screenshots let's just go with the PoliceViewController that is presented after the Police Button is pushed) you have a button in your Navigation Bar that is pointing back to the Main Menu (Screenshot says Main). The IBAction connected to that button should have the [self dismissModalViewController] statement if you want to have the user return back to the main menu. The same would go for every other Modal Window you are stacking up on the view, each one that is presented needs to have it's own Dismiss within it's own Code, not in the Parent view that is presenting it.
mavrik5150 is offline   Reply With Quote
Old 07-30-2011, 01:01 AM   #8 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 27
AnthonysABAMF is on a distinguished road
Default

Quote:
Originally Posted by mavrik5150 View Post
Well firstly you don't want to replace the [NAME release] statement, since you need that to release the memory that was retained when creating your object.

I did say where you should put it, I just didn't give you any code. Figured you would find that part yourself. Based on your screenshots you don't want the present and dismiss code in the same action, that does nothing. On each New View Controller you are calling (so looking at your screenshots let's just go with the PoliceViewController that is presented after the Police Button is pushed) you have a button in your Navigation Bar that is pointing back to the Main Menu (Screenshot says Main). The IBAction connected to that button should have the [self dismissModalViewController] statement if you want to have the user return back to the main menu. The same would go for every other Modal Window you are stacking up on the view, each one that is presented needs to have it's own Dismiss within it's own Code, not in the Parent view that is presenting it.
Oh sorry, didnt quite see what you said.

Alright, so instead of the "Main" button being linked to:
Code:
-(IBAction)pushViewUCF {
    iUCFViewController *ucf = [[iUCFViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:ucf animated:YES];
[ucf release];}
it will be linked to:
Code:
-(IBAction)pushViewUCF {
    iUCFViewController *ucf = [[iUCFViewController alloc] initWithNibName:nil bundle:nil];
[self dismissModalViewControllerAnimated:YES];}

Does that look like it'd be correct??
AnthonysABAMF is offline   Reply With Quote
Reply

Bookmarks

Tags
mvc, release

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: 393
14 members and 379 guests
7twenty7, blasterbr, buggen, chiataytuday, dre, fiftysixty, HemiMG, jimmyon122, jonathandeknudt, LEARN2MAKE, nyoe, pungs, tymex, UMAD
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,668
Threads: 94,121
Posts: 402,902
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jonathandeknudt
Powered by vBadvanced CMPS v3.1.0

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