im trying to load another nib of a UIViewController after expected time. Everything does work but wenn i load the UIViewController i get a exception when it is called. I'm doing it that way:
UIViewController *overView = [[UIViewController alloc] initWithNibName:#"overView2" bundle:nil];
[super presentViewController:overView animated:YES completion:nil];
i also tried to insert [NSBundle mainBundle] instead of "nil" but the exception still occures.
When i push the UIViewController in following was, no exception occures but after the first view is removed nothing happends:
[self.parentViewController addChildViewController:overView];
i were searching long time but couldn't find a solution...
SOLUTION
I just found the mistake.
I imported the H-File of the UIViewController in the M-File where i wanted to load the new View.Than i created a new object and passed it through.
overView2 *overView = [[overView2 alloc] init];
[self presentViewController:overView animated:YES completion:nil];
sorry, I'm new to objectiv-c...maybe will help some other beginners too :P
A standard implementation of presenting a view controller is:
[self presentViewController:overView animated:YES completion:nil];
Unless I'm missing something. Is there any more information that you can give?
Related
Can anyone provide me source code to call storyboard programatically in iOS 7 without using any segue. I am new to iPhone development.
Thank in advance
i am using like this :
UIViewController *pageOneController = [[UIViewController alloc]init] ;
[self.presentedViewController:pageOneController animated:YES completion:nil];
NSString * storyboardName = #"Main.Storyboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"pageOne"];
[self presentViewController:vc animated:YES completion:nil];
and i am getting this error:
[self.presentedViewController:pageOneController animated:YES completion:nil]; has error saying No visible #interface for 'UIViewController' declares the selector ':animated:completion:'
The error you are getting has nothing to do with Storyboard. Your code is a big mess and this is the line that crashes your app:
[self.presentedViewController:pageOneController animated:YES completion:nil];
From the error message you can understand, that presentedViewController property does not respond to this selector animated:completion:. So what you are doing wrong here is probably referencing the presentedViewController property instead of calling presentViewController method.
Try fixing this line with:
[self presentViewController:pageOneController animated:YES completion:nil];
Notice the difference that I removed the dot between self and presentViewController and changed from presentedViewController to presentViewController. This is the correct call and I am assuming that self is some kind of UIViewController class.
Take a look on this:
UIStoryboard *theStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *theViewController = [theStoryboard instantiateViewControllerWithIdentifier:#"viewController"];
And then you can just push the view using modal presentation.
But my recommendation is to get rid of Storyboards and go directly to code the interfaces with Objective-C. You'll have a better performance and control over them. And if you're learning about Objective-C programming you'll find coding interfaces, more interesting and educational than create them with Storyboards.
Here is the current code I have:
(IBAction)signup:(id)sender {
SignUp *signUp = [[SignUp alloc] init];
signUp.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:signUp animated:YES];
I am only getting an error on the bottom line. It reads: "No visible #interface for 'loginView' delcares the selector 'presentViewController:animated.'
Here is what I do not understand... I interfaced loginView as a child of the UIViewController class... This is where presentViewController is declared. Why is it telling me it can't find anything and how do I fix it?
Thank you ahead of time!
Are you sure that presentViewController:animated: is declared in UIViewController? In my docs it's listed as presentViewController:animated:completion:. You can have an empty completion block if you don't have anything to do there.
[self presentViewController:signup animated:YES completion:^(){}];
I have the following Objective-C code:
MainMenu *main= [[MainMenu alloc] initWithNibName:nil bundle:nil];
[[self navigationController]pushViewController:main animated:YES];
NSLog(#"hello");
I have a class called 'MainMenu' with a corresponding header file and xib file. No matter what I do, it simply won't show. I have confirmed that the code gets to the above, because of the NSLog('hello').
I've been pulling my hair out for hours now and I simply cannot get to the bottom of it.
I hope someone can help,
Edit - still having problems...
Here are some screenshots of my project setup:
Ok, so I tried this:
MainMenu *main= [[MainMenu alloc] initWithNibName:nil bundle:nil];
[[self navigationController]pushViewController:main animated:YES];
[self.view addSubview:main.view];
But it still doesn't work...
Many thanks in advance,
The fact that initWithNibName is nil should not be the problem because if it is given nil it looks for a nib with the exact name of the class.
Two things:
1) Make sure you have run a clean recently and make sure that file is correctly being loaded.
2) Make sure navigationController is not nil, if it is then you need to make sure you make a navigation controller if you are not intending on using a navigation controller, consider using:
- (void)presentModalViewController:(UIViewController *)modalViewController
animated:(BOOL)animated
Why are you setting the nibName to nil? If the name of the nib is MainMenu, then you want:
MainMenu *main= [[MainMenu alloc] initWithNibName:#"MainMenu" bundle:nil];
[self.navigationController pushViewController:main animated:YES];
[main release];
Are you sure that you have a UINavigationController in order to push a new view?
Hope that Helps!
Dont pull your hair just look at your code closely: You have nil in your initWithNibName. Whats MainMenu is it a viewController or what ? and place your correct nib for your to get Hello.
Updated as asked :
MainMenu *main= (MainMenu *)[MainMenu alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main];
[self.navigationController presentModalViewController:nav animated:YES];
NSLog(#"hello");
I guess the issue is that you do not have a navigation controller set up .Try to present the view controller by
[self presentModalViewController:main animated:YES];
Verify that the object owner is in fact MainMenu and the view is connected.
In the MainMenu NIB, select File's Owner and the click on the Identity Inspector. Class should match your VC class name.
Then select the main View in your NIB and click on the Connections Inspector. The view outlet should be connected to your File's Owner.
If those are both set correctly, then post some more surrounding code. Notable point, if those are both set,
MainMenu * main= [[MainMenu alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:main animated:YES];
will load the correct NIB and display it.
What are you seeing? Another point if MainMenu is a subclass of some other VC with a NIB you will have to change the base class' init to override the default behavior, for example:
self = [super initWithNibName:nibNameOrNil == nil ? #"BaseViewController" : nibNameOrNil bundle:nibBundleOrNil]
But in that case you would have to specific the NIB that will override the base view controller's.
Post more code and let us know what you are seeing when you run.
I have some view controller which I call with the following method:
myViewController *myView = [[myViewController alloc] initWithNibName:nil bundle:nil];
myView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:myView animated:YES];
[myView release];
if I use the app a few times I get a memory warning and the app freezes for a few seconds! I think the reason is that i switch the view but not discharged the old one !!?!!?!!
(i set my outlets to nil and release them)
how can I unload the old view after switching to the new one?
Thanks in advance
When switching the view be sure to call dismissModalViewController:(BOOL)animated on myViewController.
In the class that launch the modalViewController you could make a property for the modal viewcontroller which you retain. Then you could write something like this.
//This would be in an action or something...
if (self.myViewControllerProperty == nil) {
self.myViewControllerProperty = [[[MyViewController alloc] initWithNibName:nil bundle:nil] autorelease];
}
[self presentModalViewController:self.myViewControllerProperty animated:YES];
Then instead of setting the
myView.modalTransitionStyle =
UIModalTransitionStyleCoverVertical;
Move that code to the modalViewController and write self.modalTransitionStyle = UIModalTransitionStyleCoverVertical; I think that looks cleaner, keep the configuration of each viewcontroller separted don't mix it up.
And as the maclema said, call dissmissModalViewController, but you probably are doing that...
Could be any number of problems but you don't need to (and can't) unload the old view. Make sure you are releasing objects and setting outlets to nil in viewDidUnload of all of your view controllers. viewDidUnload will be called when a memory warning occurs so if you don't handle it correctly you'll have leaks and can crash. Other than that, hard to know what else your app is doing that is contributing to the crash.
In order to speed up my app, I've create three different UIViewController in AppDelegate and it has readonly property for the controllers. Those controllers are used for navigation controller.
If I tap a button on the root view, I just show another view using pushViewController method. Let me show you some code for this here.
UIViewController* controller = delegate.anotherViewController;
[delegate.navigationController pushViewController:controller animated:YES];
At first time, this work well, but if I navigate back and tap the button again, I've got a signal 'EXC_BAD_ACCESS' at second line.
What's wrong? And, how can I prepare all of my view controllers at the beginning, not create them when they are needed?
Most of the time EXC_BAD_ACCESS means that you've released an object and you're trying to reuse it without retaining it.
Look if you have released your viewController too early and whether you are (re)using it the right way or not...
I had the same problem. My code was
AddMedia *info = [[AddMedia alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:info animated:YES];
[info release];
I was releasing my viewCOntroller which was crashing the app.
When I commented that line, It worked seamlessly. The code after the change is:
AddMedia *info = [[AddMedia alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:info animated:YES];
// [info release];