I present a modalViewController that is actually a navigation controller with one view, and a custom navigation bar. The modal view appears fine as expected, but when I attempt to remove it from view using [self dismissModalViewControllerAnimated:YES], I am hitting a "-[UINavigationController modalViewController]: message sent to deallocated instance". Can't seem to figure this out. Any ideas?
Instantiating the ModalViewController:
// Make a navigation controller and add the view inside it
MyViewController *evc=[[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
//UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:evc];
UINib *nib = [UINib nibWithNibName:#"UINavigationBarWithBackgroundImage" bundle:nil];
UINavigationController *nvc = [[nib instantiateWithOwner:nil options:nil] objectAtIndex:0];
[nvc setViewControllers:[NSArray arrayWithObject:evc]];
evc.delegate=self;
[evc release];
[self presentModalViewController:nvc animated:YES];
[nvc release];
and trying to remove it. This is where the error comes in:
[self dismissModalViewControllerAnimated:YES];
Not sure about this, but try it anyway:
Remove
[nvc release]
and see if
[self dismissModalViewControllerAnimated:YES];
now works.
Is there a reason you are loading two seperate nibs to show this modal? You do not need to load a nib containing a navigation controller to get this working.
Try something like this:
// Make a navigation controller and add the view inside it
MyViewController *evc= [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:evc];
evc.delegate=self;
[self presentModalViewController:navController animated:YES];
[evc release];
[navController release];
Related
I have a tabbar in my project and each tab bar has a tableview.
I want to open a detail screen when click a row in a tableview as follows. But nothing happens.
Where's the mistake I'm doing. How should I set up a logic.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailScreen *detail = [[DetailScreen alloc] initWithNibName:#"DetailScreen" bundle:nil];
[self.navigationController pushViewController:detail animated:YES];
[detail release];
}
There are many possible reasons nothing is happening when you click on a cell.
Put a break point in this method. Is It even being called?
After the App has stopped at the breakpoint, go to the console type po detail after the instance is initialised. Make sure it's not (null)
Also try typing po [self navigationController] to check whether the navigation controller exists.
You've probably not got a navigation controller. How are you creating the tabbarcontroller? in interface builder or through code in the AppDelegate's didFinishLaunchingWithOptions: method?
Have you done this?
YourViewController *yourVC = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourVC];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, nil];
try this,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailScreen *detail = [[DetailScreen alloc] init];
[self.navigationController pushViewController:detail animated:YES];
[detail release];
}
I guess you don't have a navigation controller so
[self.navigationController pushViewController:detail animated:YES];
will not work.
use
[self.view addSubview:detail.view]
or
[self presentModalViewController:detail animated:YES];
instead
If your project is UITabBarViewController based application, i dont think your can navigate to another view using pushViewController unless you have navigationController in your project.
Add your view controller(your table view containing controller) into navigation controller and then start using
DetailScreen *detail = [[DetailScreen alloc] initWithNibName:#"DetailScreen" bundle:nil];
[self.navigationController pushViewController:detail animated:YES];
[self.navigationController pushViewController:detail animated:YES];
Instead move your detail push code to another method and call:
[self performSelector:#selector(myMethod:) withObject:nil]
I implemented a splitview using 2 UITableViews and a UIViewController. Showing both on the screen with their own data is working fine.
Now in my DidSelectRowForIndexPath I did the following:
DetailViewController *nextController = [[DetailViewController alloc] initWithStyle:UITableViewStylePlain];
NSMutableArray *objects;
objects = [[NSMutableArray alloc] initWithObjects:#"A", #"B", nil];
nextController.title = #"Filter";
[nextController SetArray:objects];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:nextController];
[self presentModalViewController:nc animated:YES];
//used this before [self.navigationController pushViewController:nextController animated:YES];
[FilterView deselectRowAtIndexPath:indexPath animated:YES];
Maybe you know a better method as what I did to present the nextController
The nextController is always showing up from the bottom and moving to the top. How can I accomplish this default sliding animation where the detail view comes into the view from the right side?
If you have started the app from the master/detail template while creating the project. Then it will have the navigation controller set automatically in the appDelegate didFinishLaunching method so in the didSelect methods you have to just use
`[self.navigationController pushViewController:vc animated:YES];`
instead of
[self presentModalViewController:nc animated:YES];
Here is a sample code which uses split view with navigation to and from root view.
First you need to confirm that you have UINavigationController at base then you can pushViewController:nextController
[FilterView deselectRowAtIndexPath:indexPath animated:YES];
DetailViewController *nextController = [[DetailViewController alloc] initWithStyle:UITableViewStylePlain];
NSMutableArray *objects;
objects = [[NSMutableArray alloc] initWithObjects:#"A", #"B", nil];
nextController.title = #"Filter";
[nextController SetArray:objects];
[self.navigationController pushViewController:nextController animated:YES];
I am facing the problem that when I push my viewcontroller in the navigationcontroller all it does is changing the navigationbar and showing the standard background but no view is to be seen. My code for pushing the viewcontroller into the navigationcontroller looks like:
Viewcontroller1 *viewController = [[Viewcontroller1 alloc] autorelease];
[[self navigationController] pushViewController:viewController animated:YES];
But, if I initialise the viewcontroller by creating IBOutlets for it, it works just fine. But the reason why I am not doing that is because I later on needs to pass some parameters to the class on initialization.
Thanks for your time.
You have to initialise your view like
if you have xib then
Viewcontroller1 *viewController = [[[Viewcontroller1 alloc] initWithNibName:#"Viewcontroller1" bundle:nil]autorelease];
[[self navigationController] pushViewController:viewController animated:YES];
if you haven't xib
Viewcontroller1 *viewController = [[[Viewcontroller1 alloc] init]autorelease];
[[self navigationController] pushViewController:viewController animated:YES];
I have in my app class UINavigationController (with NIB) and I want to open this as a ModalView.
I do that so: (ColorInfo is just this UINavigationController class)
ColorInfo *InfoScreen = [[ColorInfo alloc] initWithNibName:#"ColorInfo" bundle:[NSBundle mainBundle]];
[InfoScreen setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:InfoScreen animated:YES];
It displays me an empty UINavigtionController element. Tell me please how could I open ColorInfo (as UINavigationController) in ModalView, where I will be able to navigate through?
I thought I can complete ColorInfo with all pushViewController methods and then open it over another screen in ModalView.
Tell me how to reach this effect.
From what you've stated you've inherited UINavigationController in ColorInfo which is not what you want. You want ColorInfo to be the root view of a UINavigationController like so
ColorInfo *InfoScreen = [[ColorInfo alloc] initWithNibName:#"ColorInfo" bundle:[NSBundle mainBundle]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:InfoScreen];
[self presentModalViewController:nav animated:YES];
I recommend you read the navigation controller documentation for further clarity.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
Use this with InfoScreen controller and DON'T subclass UINavigationController ...
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:InfoScreen];
[navController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:InfoScreen animated:YES];
demo works as expected, no problems. But now I'm trying to integrate it into my project. I use no xib-s, code only:
OAuthTwitterDemoViewController *vc = [[OAuthTwitterDemoViewController alloc] init];
[[UIApplication sharedApplication].keyWindow addSubview:vc.view];
[vc release];
it compiles and runs with no errors, but the actual OAuthTwitterDemoViewController is never visible. I've also tried it from a custom viewController with [self.view addSubview:vc.view]
What's the secret??
Update:
OK, here's what I did with NavigationController:
TwitterAuthViewController *vc = [[TwitterAuthViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
[vc release];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
OK, the problems seems to be that I called [self presentModalViewController: controller animated: YES] from ModalViewController->NavigationController. That's where Cocoa touch OR Twitter-OAuth-iPhone (I don't really know which one exactly) have a problem. But this is how I need it.
Solution would be, as Ben already said, simply to push SA_OAuthTwitterController like [self.navigationController pushViewController:controller animated: YES];.
The only remaining problem is that SA_OAuthTwitterController internally creates own NavigationController bar, so that now I have 2 navigation bars visible.