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

Kingbombs

macrumors member
Original poster
Jun 24, 2009
98
0
Hey,
So i have bassicly a main menu, and when the user presses a certain button the buttons on the view are set to hidden and then i load the view up (create an instance of the class which is a UIViewController and then add as a subview)
now i want a button to get back to main menu
if i do [self.view removeFromSuperview];
Then i just get a blank screen
The problem here is that, i make the button's not visible, so i have a method that makes all the main menu buttons visible again, but i can't find a way to call that method
i've tried to create an instance of the parent view and then call the method and then remove from the superview but that doesn't work (didnt think it would)

i tried something like:
UIView *parent = [self superview];
if (parent)
[parent callMethod];
but that doesn't work either

If anyone could help me out that would be appreciated!
btw i did imported the class file so i could call the method from the instance of the class
 
Instead of adding as a subview you might want to try presenting a modal view and then dismissing it when you want to go back to the menu. You don't even need to animate the transition if you don't want to.
 
thanks for the reply
i have been reading the apply documentation on it,
do you know of any good code examples of this being used?
Everything i found or saw was using table views and things like this, i just want to create a button which can then call dismissModelViewController so i can get back to the root view
 
You should use a navigation controller. If you don't want to see a navbar you can make it hidden. Then it's a simple matter of pushViewController, popViewController.
 
i got it working
apple docs had this which lead me in a wrong direction:
[[self firstNavigationController] presentModalViewController:secondNavigationController animated:YES];
just need self not firstNav...
thanks for the help
 
I have a few problems,
It seems to works when i click a button to load that view, the view has a timer and it enters information in the database,
then when i click to leave the view i go back to main menu
now if i click on the same button to load that view again, it crashes
If i don't get the timer to run then i can go back and fourth between the views, but when the timer is turned on then i cannot go back onto the view after i have been on it once

I wasn't sure what to do with this or if there is something i should call before dismissModalViewController
maybe in the viewdidUnload method?

sometimes the timer is set to [timer invalidate];
which is what i call when the button is pressed to return to the menu (which means i invalidate it twice sometimes, which causes an error)
i tried:
if ([timer isValid])
[timer invalidate];

but this seemed to cause an error at run time

if anyone knows of anything that can help for any of those problems that would be good thank you
 
So i had it fixed initially, i was releasing the timer in the dealloc method but if i did [timer invalidate]; already, then it would throw an error
(but if i just have [timer release]; in the dealloc method, it wouldn't stop the timer)
so release it when i close the view now when the button is pressed

But if the timer has already been set to invalidate - [timer invalidate];
then when i try if ([timer isValid])
it throws an error:
btw this is timer declared in .h: NSTimer *countdownTimer;
Code:
04/09/2009 12:06:08 Baseball[997] *** -[NSCFData isValid]: unrecognized selector sent to instance 0xd4c340 
ON THE NEXT LINE IT ALSO HAS:
04/09/2009 12:06:08 Baseball[997] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFData isValid]: unrecognized selector sent to instance 0xd4c340'
There is also a stack trace i could print but i don't know if it will make any difference (is there a site on how to read stack trace or what it shows)

So if anyone could help with that, i would have thought if i did [timer invalidate] then when i did [timer isValid]; it would return no and not cause that error

Also on a side note is there a very quick and easy way to put a background picture on a view? (spend most of my time on opengl so view based and IB stuff im a noob on, and figured i should use it rather than opengl to learn it)
I just have a picture that is the size of the screen and just want it as the background for all the views

thanks anyone who can help
 
From the NSTimer class Reference:

To request the removal of a timer from an NSRunLoop object, send the timer the invalidate message from the same thread on which the timer was installed. This message immediately disables the timer, so it no longer affects the NSRunLoop object. The run loop removes and releases the timer, either just before the invalidate method returns or at some later point.

Setting your ivar to nil prevents your code from referencing an already released object.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.