I'm working on a word search puzzle game for the iphone and I'm trying to implement a restart button for the app. The restart button should be able to initialize a new view controller, generate a new puzzle, and display the new puzzle.
As of now, in the puzzle game view, I have a button that on-click it opens the pause menu view using a modal segue.(The pause menu have three buttons, resume, restart, main menu.) I then made the puzzle game controller a delegate of the pause menu, that receives the notification when the buttons are pressed. The resume and main menu button works, but I'm having trouble reloading the view with the restart button. The puzzle is inside a container view, that has a collection controller that creates the grid and displays the letter.
With the current code I have, when I click the restart button, all i see a black screen that only shows the navigation bar. But once I click the pause menu button(located in nav bar) and then click the resume button in the pause menu, i see the view with the new generated puzzle.
Below is the code in the pauseMenuController:
- (IBAction)IBARestart:(id)sender {
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
[self.delegate goToRestart];
}
Now here is the code in my puzzleGameController:
-(void)goToRestart{
self.view = nil;
[self.view.window setNeedsDisplay];
PuzzleCollectionControllerViewController *puzzleInstance = [self.childViewControllers lastObject];
puzzleInstance.view = nil;
[puzzleInstance.view setNeedsDisplay]; // I tried reloading the cointainer view too, but it still shows black screen
}
Anyone have any idea why is it showing a black screen? Thanks in Advance
I'm not sure if this is enough code, to get your problem..
But my concerns on this are:
Why do you "nil" self.view on restart? If you do this, the view is "nil" and therefore won't display anything, same for puzzleInstance.view.
You could nil / free the memory for this on viewDidUnload, as the view will get set again on viewDidLoad, but normally I just "nil" / "dealloc" any properties, outlets etc. (on viewDidUnload or dealloc, depending on where I set / re-set them) and not the view itself.
"setNeedsDisplay" will just "redraw" the view, but if it's nil, I'm afraid there is nothing to redraw. So I'm pretty sure that's your problem here.
What is different, or what is happening when you press "resume" (code?).
Related
In my project I am using a storyboard.
There is view controller MyViewController. MyViewController has button, on click of button it opens a Isgl3DViewController.
Isgl3dViewController has an animated 3d object. Isgl3dViewController also has a Close button, which dismisses the Isgl3dViewController and moves to MyViewController.
Now, when I am doing this first time, everything is working fine. I am able to see animated object and able to move MyViewController on click of Close Button.
But second time, when I click on MyViewController's button to display animation, Application being crashed again and again.
When it's working fine in first time then why app crashes in second time? Please help me out this.
For Reference I am attaching screenshot.
had the same problem, in my case because i add UI elements over the isgl3dview.
my workaround was substitute the UIView by a HUD.
So I have an iPhone app. It has a simple structure, all based on a UINavigationController.
I have a storyboard that has one view, a segue to another view, etc. Now this other view has a UITextView that I do not want to edit on this screen - if the user taps this, I want it instead to fly over to a second screen which basically has the same text view, but this one is full-screen, and the user will edit the text on that screen before returning to the previous screen.
So I capture the textViewShouldBeginEditing method. I previously, in the storyboard editor, manually created a push segue from the previous view controller to this new view controller, and named it so that I can call it by it's identity, which I do with:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
// This is called when the user clicks into the textView as if to edit it.
// Instead of editing it, go to this other view here:
[self performSegueWithIdentifier:#"editMemoSegue" sender:self];
// Return NO, as I don't actually want to edit the text on this screen:
return NO;
}
Seems reasonable. And it works. Sorta. It does in fact shoot me over to that other view. That other view's events fire up, I set it's text view to become first responder, I edit the text on that screen. Everyone's happy.
Until I want to use the back button to return to the previous view.
Then I quickly find out - my navigation stack is foobared. Most of the time, I have, for some reason, TWO instances of my new editing controller on the stack, so the first time I hit the back button I get the same stuff over again. Then, oddly, occasionally, it will work as intended, and I will see my previous controller with only one back click.
I started reading the log, and I found this:
2012-12-09 09:41:03.463 APP[8368:c07] nested push animation can result in corrupted navigation bar
2012-12-09 09:41:03.818 APP[8368:c07] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2012-12-09 09:41:03.819 APP[8368:c07] Unbalanced calls to begin/end appearance transitions for <SecondController: 0x83881d0>.
So obviously, I'm doing something incorrectly here. The question is, what? And how do I do what I want in the way that correctly appeases the tiki gods of the iPhone framework?
Check to see if the textViewShouldBeginEditing is being called twice. I've noticed that these kinds of delegate calls sometimes are.
How is your #"editMemoSegue" being created on the storyboard? is it created from the textView? if it is then you should recreate it directly from the view controller or from the top status bar on the view controller that way it wont be called twice when you touch the trigger object and when you call it programmatically.
I did a simple view based application.
what i did is creating view additional to existing view.
means there is one view named main in .xib file additional to that i am creating another view
IBOutlet UIView *view_additional;
In the main view by button click i call the view_additional view.
For the view_additional view i place navigation bar with one bar button named back.
In the back button click event i need to get back to main view.
for that in the button click action i write the fallowing code.
[view_additional removeFromSuperview];
But it is not open main view,shows a white screen.
what the wrong.
how can i get back from additional view to main view.
Thank u in advance.
for the code you used to display view_additional, instead of using self.view = view_additional
try using, on button click
[self addSubview: view_additional];
And once that's done, your code should work just fine the way you want.
When dealing with views, if you change a view, then remove it, as you did in your code, then all that will be left is the main app window. There will be no views on that window. From the look of it, you want to load up a new view, and then remove it once you're done with it. You can do this by adding the new view as a subview instead of totally changing the parent view. Another thing you can do is set an IBOutlet for the original view as well, this way you'll have an outlet for both views, and then instead of removing your additional_view from the superview, you can just switch it back. So the code for the Back Button would just be
self.view = original_view;
on back button click. I hope this isn't too confusing for you. Let me know if you have any questions.
Both methods would work for what you want to do.
I resolve my problem as
instead of [self.view = view_additional];
i use
[self addSubview: view_additional];
To get back to original view in the button click
i use
[view_additional removeFromSuperview];
MahesBabu, that is exactly What I suggested that you do. Only I offered the background info on why you should do it that way.
# MaheshBabu:
This is the common code u can use to go on next view or go on back, Just change button name which u want to press and the view name on which u want to go. For example on back button press u want to go on library view then write this code -
-(IBAction)backButtonPressed:(id) sender
{
libraryView *libraryview=[[libraryView alloc] initWithNibName:nil bundle:nil];
libraryview.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:libraryview animated:YES];
[libraryview release];
}
Let me know whether ur problem is solved or not.
While in a call, if the user wants to use my application, and if the call finishes, and the user is still in the application, the toolbar moves up, well all the view moves up, and so the toolbar now has a space in the bottom. Basically the height "Touch to return to call" has. I am using a toolbar and a navigation controller. The navigation controller moves fine, and everything in the view moves accordingly, the only problem is with the toolbar. So the question is, Is there an event, which is called after the call is finished, so I can set the frame again of my toolbar? I tried this delegate with no luck:
- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame
This one is called only when the toolbar is changing orientation.
alt text http://is.hn/downloads/IMG_0008.PNG
alt text http://is.hn/downloads/IMG_0009.PNG
Thanks.
In general setting your auto resize masks properly should fix things. Could you update with a screenshot to show exactly where the resizing issues are happening?
In this (Flip View Iphone) post, I have created a flip view for my iPhone app.
Now, I want to make sure that whenever the user hits the 'Back' button in the navigation bar, the next time around when he drills down to the flippable view, this view is in its original, non-flipped position. Currently, the app actually loads the correct view, but somehow, when you try to flip it over, it cannot doesn't load the flip view, and presents a black background only.
One solution could be to assign the flip back method ("showLessInfo") to the navigation button, and that is what I need your help for.
Alternatively, and quite likely a better idea for me would be to understand, why the flip view is not loaded the second time around.
Any suggestion is welcome!
You can override the viewWillAppear: method on your flip view's view controller and make sure behind the scenes it loads the proper view before showing (remember to call [super viewWillAppear:animated]).
Or else, you could override the viewWillDisappear and make sure things are cleaned up on the way out. It will get invoked when the user taps the back button.