How to remove view from window? - iphone

I am using Cocos2D for my main framework. In some cases, I want Cocos2D to load a nib file and have that be the view:
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
TargetPlayerViewController *myController = [[TargetPlayerViewController alloc]initWithNibName:#"TargetPlayerViewController" bundle:nil];
[window addSubview:[myController view]];
[window makeKeyAndVisible];
This works as expected, and shows the TargetPlayerViewController. Wonderful!
What I need to know is: once that view has been loaded, how can I have the view remove itself? I've tried a few different ways, but all of them result in the program crashing.
To test I have a button on the view set up which triggers this method:
- (IBAction)GTFOnow:(id)sender {
NSLog(#"GFTO");
//window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//[self.view removeFromSuperview];
//[window makeKeyAndVisible];
}
GTFOnow is a method in TargetPlayerViewController. When it is called, the current subview (that was called in the Cocos2D code above) should be removed from the window.

First of all, you shouldn't create a new window just because you want to remove a subview. Secondly, whatever else happens, this shouldn't cause the app to crash. In which class do you have the GTFOnowmethod? I suppose in the TargetPlayerViewController class?

Related

UITabBarController tabbaritem not touchable after second click

I have an UITabBarController added programmatically one ViewController as ModalViewController.
It acts perfectly normal, when touching/switchen between the tabs.
But when touching the selected tab again, the delegate didselectviewcontroller did not get called.
Strange behaviour, if I setup a new project with TabBarController template, this is acting normal and everytime I touch a tab its delegate is being called.
What I noticed, if I touch 2-5px above the tabbar, the tab is being touched and the delegate is being called.
There is no view above the tabbar, I checked this 100 times.
if I touch in the lightgray area, the touch on the tab is being fired.. thats a miracle to me, anybody any idea?
Code:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] init];
_splashScreen = [[SplashScreenController alloc] initWithNibName:#"SplashScreenView" bundle:nil];
self.window.rootViewController = _splashScreen;
[self.window makeKeyAndVisible];
if finished loading data in background,
//getting UIViewControllers from Config and adding to NSMutableArray *tbcArr;
[self.tabBarController setViewControllers:tbcArr];
self.tabBarController.customizableViewControllers = nil;
self.tabBarController.delegate = self;
[self.splashScreen presentModalViewController:self.tabBarController animated:YES];

How to fix "Unknown class RootViewController in Interface Builder file" ios6

I've read a number of similar posts but I cannot get an answer that works for me. I have this beginning in my AppDelegate:
//LOAD WINDOWS
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
self.initialViewController = [[InitialViewController alloc] initWithNibName:#"InitialViewController" bundle:nil];
[self.window setRootViewController:self.initialViewController];
} else {
self.patternViewController = [[PatternViewController alloc] initWithNibName:#"PatternView_iPhone" bundle:nil];
[self.window setRootViewController: self.patternViewController];
}
return YES;
This is working for the iPad version, but not for the iPhone. I get these messages in the console:
Unknown class RootViewController in Interface Builder file.
Application windows are expected to have a root view controller at the end of application launch
The PatternView_iPhone xib is of the PatternViewController class.
In the project summary, I have these settings:
and
The error says that there is object whose class name is RootviewController in the xib .Open the xib/storyboard as source (Right click and open as source code) and search RootviewController. Find where the tag comes and find the object and change it to valid object.

removing window from modalviewcontroller

I launch a modal view controller and in its init I have the following code:
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
viewController = [[UIViewController alloc]init];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
I need the viewController for entering some data in it. How can I release the window and viewController so that I can go back to the viewController that launched the modal view controller? At this point, after I'm done doing what I need in the modal view, I am trying:
[viewController.view removeFromSuperview];
[window removeFromSuperview];
but just end up with the modal view's parent (the one that lanched the modal view) just frozen(it's not really frozen, it is just not user interactible because there are the window and view controller in front of it and the view controller doesn't have size and background
iOS app should only contain one UIWindow.
And you can easily present UIViewController with in viewController
[self presentModalViewController:navigationController animated:animated];
Then just call in that viewController to dismiss it:
[self dismissModalViewControllerAnimated:YES];

iphone app hangs in AppDelegate (?)

No nib/IB, so I've inserted "myAppDelegate" in main and deleted the reference to main.xib in info.plist. Debug continues nicely through all five tab controllers; they seem to have gotten properly loaded into the nav controller. In fact, control passes out of the last "}" in applicationDidFinishLaunching. But there was no (visible) response back at [window addSubview:[tabBarController view]]; and [window makeKeyAndVisible]; statements, much less to the loadView within the first tab (program execution never gets there). The last line is, UIApplication _performInitializationWithURL:sourceBundleID:]. I missed a step? I executed a step improperly?
Did you create an UIWindow instance in applicationDidFinishLaunching:?
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Also, the line you call UIApplicationMain should look like this:
int retVal = UIApplicationMain(argc, argv, #"UIApplication", #"YourAppDelegate");
where YourAppDelegate is the name of your AppDelegate class.

iPhone: Popping a modalViewController off of a UINavigationController stack

Ever since I've taken one of my UIViewController subclasses and present it to the user in the form of a modal view, with presentModalViewController:animated.. I haven't been able to dismiss it using:
[self dismissModalViewControllerAnimated:YES];
I do believe this is some odd mixup with how I'm instantiating a UINavigationController on the modalViewController, with code that looks like the following (similar code is also in the App Delegate):
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
navigationController =
[[UINavigationController alloc] initWithRootViewController:self];
navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
The navigation stack works as expected, but unless I remove it, I can't dismiss the modal view controller any longer. I'm under the impression that I shouldn't be adding a subView to UIWindow more than once and that's just one of the problems.
Make sure you call dismissModalViewControllerAnimated on the parent of the modal view controller, not on the modal view controller itself.