How to access navigationController from popoverController? - objective-c

I am trying to push a new viewController into the navigationController from a popoverController but it doesnt work for me.
This is how I call to the popoverController:
PdfDetailViewController *vc=[[PdfDetailViewController alloc] initWithNibName:#"PdfDetailViewController" bundle:nil];
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 400, 280)];
vc.contentSizeForViewInPopover = CGSizeMake(700, 390);
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:vc];
[self.popoverController presentPopoverFromRect:cell.frame inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popoverView release];
[popoverContent release];
This is my code from the popoverController:
CommentsViewController *commentsViewController = [[CommentsViewController alloc] init];
commentsViewController.index = PdfID;
[self.parentViewController.navigationController pushViewController:commentsViewController animated:YES];
[commentsViewController release];
Nothing happen
Please help me... thank you!

UIPopoverController doesn't have a NavigationController unless you add one yourself.
For example
MyViewController *myViewController =
[[MyViewController alloc]
initWithNibName:#"MuViewController"
bundle:[NSBundle mainBundle]];
UINavigationController *navController =
[[UINavigationController alloc]
initWithRootViewController:myViewController];
UIPopoverController *popover =
[[UIPopoverController alloc]
initWithContentViewController:navController];

You should start by cleaning up your code so that it makes sense. Right now you are creating a UIView called popoverView for no reason and then just throwing it away. You're just confusing yourself and it's harder to understand what you are trying to accomplish when you show meaningles code.
Once you've done that, what are you trying to accomplish? Is the problem that this line doesn't work: self.parentViewController.navigationController pushViewController:? If so, I would suggest pulling it apart and logging to make sure that parentViewController and navigationController are the objects you think they are.

Related

iPhone SDK -> RightBarButtonItem disappears when loading view through AppDelegate

So I have an issue with my rightbarbuttonitem disappearing. I have two ways of loading this view, first time launch it loads it after user enters in their name (from an initial view). Second time (after the app exits), it checks if the name exists in my stored database and if it does it loads the view right away. This second time is where the button does not show.
The button was set in viewDidLoad of my view originally here (and is still set here for the first load):
if (self.navigationItem.rightBarButtonItem == nil){
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(buttonPressed)];
self.navigationItem.rightBarButtonItem = addButton;
[self.navigationItem.rightBarButtonItem retain];
}
Then in the .m of my AppDelegate, I added the button to think that would resolve it on the second load:
if(success){
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *control = [[ViewController alloc] initWithNibName:#"myNib" bundle:nil];
[control retain];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:control];
[navControl retain];
[self.window setRootViewController:navControl];
if (navControl.navigationItem.rightBarButtonItem == nil){
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(buttonPressed)];
navControl.navigationItem.rightBarButtonItem = addButton;
[navControl.navigationItem.rightBarButtonItem retain];
}
//[navControl release];
[self.window makeKeyAndVisible];
return;
Here's the declaration of the addButton in the header for App Delegate and my view's header:
UIBarButtonItem *addButton;
#property (nonatomic, retain) UIBarButtonItem *addButton
Other posts say to check viewDidLoad/viewWillAppear but putting that first blurb of code in either of those does not solve the issue.
Solved it myself, since the button was never added to the nib, initializing UIViewController doesn't help. I had to initialize my view controller.
In other words replace: UIViewController *control = [[ViewController alloc] initWithNibName:#"myNib" bundle:nil]; with: MyViewControllerClassName *control = [[MyViewControllerClassName alloc] initWithNibName:#"myNib" bundle:nil]; Hope this helps others in the future, thanks for taking the time to read this if you did!

SplitViewController with TabbarController

I am using the split View functionality in my app.I have to put tabbar in rootViewController.
But when I add controllers in tabbar and add them into split view it doesnt split.
It only shows detailViewController.
Here is the code in application did finish launching:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIViewController *viewController2,*viewController3,*viewController4;
rootViewController = [[[CategoryItemsList alloc] init] autorelease];
viewController2 = [[[SearchList alloc] init] autorelease];
viewController3 = [[[FavoritesList alloc] init] autorelease];
viewController4 = [[[Information alloc] init] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects: rootViewController,viewController2,viewController3,viewController4, nil];
splitDetail = [[splitDetailView alloc] initWithNibName:#"splitDetailView" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:tabBarController];
splitViewController = [[UISplitViewController alloc] init];
// splitViewController.tabBarItem = controller.tabBarItem;
splitViewController.viewControllers = [NSArray arrayWithObjects:nav, splitDetail, nil];
splitViewController.delegate=splitDetail;
rootViewController.splitView=splitDetail;
}
You can refer to this links. I think this is what you are looking out for:
https://github.com/mattgemmell/MGSplitViewController
http://www.raywenderlich.com/1040/ipad-for-iphone-developers-101-uisplitview-tutorial
http://mikebluestein.wordpress.com/2010/04/03/using-a-uisplitviewcontroller-to-create-a-master-detail-ipad-app-with-monotouch/
Once you add the split view then you just need to add the object of the SplitViewController to the TabBarController as one of the viewControllers
Hope this helps.

navigationBar isn't showing when I put a UINavigationController in a UIPopoverController

I'm adding a UIViewController to a UINavigationController and then setting a UIPopoverController's view to the UINavigationController. Everything is working great except that I don't get a navigationBar at the top of the popoverController. I'm creating everything like this:
QueryViewController *puvc = [[QueryViewController alloc] autorelease];
UINavigationController *nc = [[UINavigationController alloc] autorelease];
[nc pushViewController:puvc animated:YES];
self.popUp = [[[UIPopoverController alloc] initWithContentViewController:nc] autorelease];
[self.popUp presentPopoverFromBarButtonItem:[self.toolbarItems objectAtIndex:0] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popUp.delegate = self;
I've tried to set navigationBarHidden = NO and it still doesn't show up. I have this code in my viewDidLoad of my QueryViewController:
self.contentSizeForViewInPopover = CGSizeMake(500.0, 500.0);
self.title = #"Queries";
Is there something that I'm missing to display the navigationBar? I am already in a UINavigationController for my main screen, could this be part of my problem?
QueryViewController *puvc = [[QueryViewController alloc] autorelease];
UINavigationController *nc = [[UINavigationController alloc] autorelease];
Maybe your code is wrong. Where is init methods?
You have to init both your QueryViewController and UINavigationController. For the second use initWithRootViewController method.
QueryViewController *puvc = [[[QueryViewController alloc] init] autorelease];
UINavigationController *nc = [[[UINavigationController alloc] initWithRootViewController:pucv] autorelease];
//[nc pushViewController:puvc animated:YES];
If you use initWithRootViewController it's not necessary to push puvc instance.
You could try also this (I like to release memory explicity, not using autorelease).
QueryViewController *puvc = [[QueryViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:pucv];
//[nc pushViewController:puvc animated:YES];
Then at the end of your code snippet remember to release puvc and nc.
[puvc release];
[nc release];
P.S. Check the code because I've written without XCode.

UIModalTransitionStyleFlipHorizontal doesn't work

I try to change the modalTransitionStyle property of my modal view. Every style work except for FlipHorizontal. If I choose this, nothing happens.
I have an UINavigationController which should be flipped in.
Heres the code:
UINavigationController *loginNavCon = [[UINavigationController alloc] init];
loginNavCon.navigationBar.barStyle = UIBarStyleBlack;
// push login view
LogInViewController *liVC = [[LogInViewController alloc] initWithStyle:UITableViewStyleGrouped];
[loginNavCon pushViewController:liVC animated:NO];
[liVC release];
// show login view
loginNavCon.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.window.rootViewController presentModalViewController:loginNavCon animated:YES];
[loginNavCon release];
Thanks for your help.
Ok, I figured it out!
The point is to set it in the pushing UIViewController, not in the pushed one.
So in my example code it has to look like this:
UINavigationController *loginNavCon = [[UINavigationController alloc] init];
loginNavCon.navigationBar.barStyle = UIBarStyleBlack;
// push login view
LogInViewController *liVC = [[LogInViewController alloc] initWithStyle:UITableViewStyleGrouped];
[loginNavCon pushViewController:liVC animated:NO];
[liVC release];
// show login view
/** changed **/
self.window.rootViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
/*************/
[self.window.rootViewController presentModalViewController:loginNavCon animated:YES];
[loginNavCon release];

Cannot get Twitter-OAuth-iPhone to work

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.