issue in DDMenuController menuViewController like facebook - iphone

My First Question
DDMenuController(facebook split menu) Must be on RootviewController? it can not be on other viewController which we push on rootViewCotroller?
if answer is no then
Second Question
i am trying to make split viewController like facebook for that i am using this sample
https://github.com/devindoty/DDMenuController
now what i want to do is i dont want set DDMenuControl as rootviewcontroller in appdelegate in my rootcontrollers there are view buttons which push my all other ViewController
so what i want is from my rootViewController' Buttons i push another controller and then that view should get pushed and same time there should be DDMenuController too
so what will happen is on navigation bar there wont be back button there will be splitting screen button like facebook and from there i can go to another view controller
now let me tell you what i have achieved so far my rootViewController is getting displayed and then from there i push my other ViewController and on navigation bar splitting button is also getting displayed but its not working let me should you code to make this all clear
this is how i set my rootViewContoller in app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
FirstPadViewController *mainController = [[FirstPadViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:mainController];
self.window.rootViewController = navController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
so it get displayed with some buttons from where i can push my other viewController
this is how i push my other ViewController
- (IBAction)goToCamera:(id)sender {
AROverlayPadViewController *svController = [[AROverlayPadViewController alloc] init];
[self.navigationController pushViewController:svController animated:YES];
[svController release];
svController = nil;
}
so AROverlayPadViewController is getting pushed
and in AROverlayPadViewController's viewWillAppear this is what i do for achieving splitting screen like facebook
-(void)viewWillAppear:(BOOL)animated{
DDMenuController *rootController = [[DDMenuController alloc] initWithRootViewController:self];
LeftController *leftController = [[LeftController alloc] init];
rootController.leftViewController = leftController;
}
splitting button is getting displayed but when i press it is not working
now i really dont have any clue what to do any help will be highly appreciated

Answering the first question: actually it's a yes. This is how you do it, in the method that sends you to your nextScreen:
-(void) goToAnotherController {
OtherViewController *nextScreen = [OtherViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:nextScreen];
DDMenuController *menuController = (DDMenuController*)((AppDelegate*) [[UIApplication sharedApplication] delegate]).menuController;
[menuController setRootController:navController animated:YES];
}

Related

How to code a back button on the a navigation bar using a bar button item

I'm having trouble coding a button to go to the previous page. I was able to do it to go to the next page thinking if I did the same thing but changed it a bit it would work in reverse. Unfortunately, I come up with a lot of errors I can't resolve because it won't allow me to use the release function.
This is this the code that helps it to work going to the next page fine:
#import "ViewController.h"
#implementation ViewController
-(IBAction)btnClicked:(id) sender
{
//add the view of the view controller to the current View---
if (menuView==nil) {
menuView =
[[MenuView alloc] initWithNibName:#"MenuView"
bundle:nil];
}
[self.view addSubview:menuView.view];
}
-(void)dealloc {
[menuView release];
[super dealloc];
}
How do I do it so that a back button will go to the previous page though.
It's pretty simple, use this :
-(IBAction)back:(id) sender
{
[menuView.view removeFromSuperview];
}
But, I would suggest not using addSubview: for many views as it would be complex way to do. Use UINavigationController as #Paul.s suggested.
The way you are doing this is not quite correct and I would suggest doing some reading to get familiar with iOS programming.
Your program structure should be: create a navigation controller (2) to manage the stack of view controllers giving it a viewController (1) to act as it's root.
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// 1
FirstViewController *firstViewController = [[FirstViewController alloc] init];
// 2
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release]; firstViewController = nil;
self.window.rootViewController = navigationController;
[navigationController release]; navigationController = nil;
[self.window makeKeyAndVisible];
return YES;
}
This will display your first view controller inside a UINavigationController. A UINavigationController is responsible for managing a stack of UIViewController's and giving you UI to navigate back down the stack as well as calling all the appropriate presentation related methods on a UIViewController at the correct times e.g. viewDidLoad. You should check out The View Controller Programming Guide for lots of info
Then inside your first view controller you do something like this to respond to the button:
- (IBAction)buttonClicked:(id)sender;
{
SecondViewController *secondViewController = [[SecondViewController alloc] init];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release]; secondViewController = nil;
}
This creates a new view controller and pushes it onto the stack.

UIActivityIndicatorView is not working (getting Facebook permissions affecting UIActivityIndicatorView)

I have a tabbarcontroller with three tabs/viewcontrollers.
When I first start my app, with my ActivityIndicator set to be visible and animated - courtesy of interface builder - it works fine.
However when I click a button an internet window opens to Facebook in order to get the user's permission.
Once the Facebook part is taken care it returns to my app but the ActivityIndicator is not longer animated - it is still visible though, just frozen.
If I switch to another tab/viewcontroller and then come back to the tab/viewcontroller with the ActivityIndicator everything works fine.
Is there a way to refresh my ViewController so that I don't have to programmatically make the ViewController switch back and forth? Or any other suggestions?
/* I searched the forums and I saw a similar question. It appeared that there was a broken connection. Therefore I'll include the code where I add the ViewController (i.e., "controller" to my tabbarcontroller). */
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
controller = [[DemoAppViewController alloc] init];
controller.view.frame = CGRectMake(0, 20, 320, 460);
controller.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"movieAppBackground.jpg"]];
MyTabBarViewController *vc2 = [[MyTabBarViewController alloc] init];
SecondViewController *vc3 = [[SecondViewController alloc] init];
controller.title = #"Intro Screen";
vc2.title = #"Explore";
vc3.title = #"Send a Pic";
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = [NSArray arrayWithObjects:controller, vc2, vc3, nil];
self.theTBC=tbc;
[controller release];
[vc2 release];
[vc3 release];
[tbc release];
[self.window addSubview:tbc.view];
[self.window makeKeyAndVisible];
return YES;
}
whereever u have used NIB file to show with viewcontrollers u have to create them with initwithname
Example
SecondViewController *r=[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
like this change whereever u have used nib file to create instance,
i meaned for all custom viewcontrollers u have created with NIB file

How to show UINavigationController on view

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:#"MainPage" bundle:nil];
UINavigationController *nav_obj = [[UINavigationController alloc] initWithRootViewController:overviewViewController ];
[self.viewController presentModalViewController:nav_obj animated:YES];
[overviewViewController release];
[self.window makeKeyAndVisible];
return YES;
}
This code shows the blue bar of navigation controller, but no buttons on it.It seems like to be that the UINavigationController allocated as empty.
Who knows what problems is?
UPD:Archive http://www.mediafire.com/?lbjjvl6fcue2q18
Please help me, I'm new in objective-c
You need to create the button for it, for example:
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:launcherView action:#selector(endEditing)];
self.navigationItem.leftBarButtonItem = doneButton;
[doneButton release];
The correct way to use a UINavigationController is to push view controllers on to it. That way they will be stacked and the navigation bar will be populated with a back button when it is case (i.e., when you can actually go back to a previous controller). You control the label that appears in the "back" button by defining the title of the controllers you push.
The technique shown in another answer (setting explicitly the button) is useful with defining the right button, if you ever need one.
You could try with this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:#"MainPage" bundle:nil];
UINavigationController* navigation = [[UINavigationController alloc] init];
[navigation pushViewController:overviewViewController animated:NO];
[overviewViewController release];
[window addSubview:[navigation view]];
[self.window makeKeyAndVisible];
return YES;
}
Instead of doing:
UINavigationController* navigation = [[UINavigationController alloc] init];
[navigation pushViewController:overviewViewController animated:NO];
you could also use initWithRootController, but to display the general case of how you push a view controller I preferred this one.
Notice that since you are pushing just a root controller, you should see no back button at the moment, but if you push a second view controller, then it will appear.
EDIT: I gave a look at your project. Summary of what you should try and do:
objects you need in your NIB: File's Owner (UIApplication), First Responder, FBFun App Delegate (iVkAppDelegate), Window (UIWindow); remove the rest;
File's owner delegate outlet is FBFun App Delegate;
FBFun App Delegate window outlet is Window.
With this simple setup (more or less what you have), use this code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController* navigation = [[UINavigationController alloc] init];
//-- MainPageDialog *overviewViewController = [[MainPageDialog alloc] initWithNibName:#"MainPage" bundle:nil];
iVkViewController *overviewViewController = [[iVkViewController alloc] init];
overviewViewController.title = #"First";
[navigation pushViewController:overviewViewController animated:NO];
iVkViewController *overviewViewController2 = [[iVkViewController alloc] init];
overviewViewController2.title = #"Second";
[navigation pushViewController:overviewViewController2 animated:NO];
[overviewViewController release];
[window addSubview:[navigation view]];
[self.window makeKeyAndVisible];
return YES;
}
In the code above, as you notice, I instantiated twice your iVkViewController just to have a second controller to push onto the navigator.
Please, delete your existing app from the simulator, and the run this in order to see that the navigation bar is correctly created and you can go back from the second controller to the first one.
I removed usage of MainPageDialog, because the MainPage nib has many problems.
But I hope this skeleton is sufficient for you to go forward with your development.
You had missed the line as you are not adding view to window.Add this line in your code
[window addSubview:nav_obj.view];

How to show a secondary view before the main view?

I'm wanting to have my app (on launch) load a view that I have created over the top of the original view, then when a button is clicked the top view will disappear and show the main view underneath. I know this is terribly simple, but how would I do this? Maybe push the view in viewDidLoad?
Use a navigation controller
MyViewController *myView = [[MyViewController alloc] init];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:myView];
My2ndView *secondView = ....
[navControl pushViewController:secondView animated:NO];
[window addSubView:navControl.view]
This can be incredibly simple. When the user clicks the button, just do this
secondViewController.view.hidden = YES;
Just add the two views in your delegate, and do that in your delegate.
If you prefer, just do it "in" secondViewController! self.view.hidden = YES;
It sounds like you're just doing something simple ...... no need to bother with a view controller.
You ask how to display the second view, just like this ..
-(BOOL)application:(UIApplication *)applic`ation
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[window addSubview:yourMainView.view];
[window addSubview:theTemporaryView.view]; // it goes on top
[window makeKeyAndVisible];
application.idleTimerDisabled = YES;
return YES;
}
-(BOOL)eliminateTempView // example, when the user clicks on the button
{
theTemporaryView.view.hidden = YES;
[theTemporaryView release];
}
Hope it helps!

iphone presentModalViewController

I have an app, inside that an UIViewController is attached on the UIWindow.
on the view of UIViewController, i have added a button and a uiview_1 of size 100x80.
this uiview_1 contains another uiview_2 as subview of same size and this uiview_2 contains a UIImageView or a UIlable at runtime (both UIImageView and UIlable are userinteraction enabled)
now on the touch/click of UIImageView, i want to show a new view using presentModalViewController, the problem is the view is shown and using back button on the navigation bar i come to the previous/main screen.
here the problem come in picture, now i am unable to touch the button or the UIImageView.
both are not responding, but app is not crashed and nor frozen.
what is wrong in that?
Plz help in this...
----- EDIT:
Approach First:
SWVController *swvController = [[SWVController alloc] init];
UINavigationController *viewNavController = [[UINavigationController alloc] initWithRootViewController:swvController];
UIViewController *pushController = [[UIViewController alloc] init];
UIWindow *win = [[UIApplication sharedApplication] keyWindow];
[win addSubview:pushController.view];
[pushController presentModalViewController:viewNavController animated:YES];
In the swvController i have back button that calls the dismissModelViewController on click >> result is the Main screen ctrls are not responding to touch – sandy 3 hours ago
Second approach:
SWVController *swvController = [[SWVController alloc] init];
UINavigationController *viewNavController = [[UINavigationController alloc] initWithRootViewController:swvController];
UIViewController *pushController = [[UIViewController alloc] init];
[self addSubview:pushController.view];
[pushController presentModalViewController:viewNavController animated:YES];
In the swvController i have back button that calls the dismissModelViewController on click >> result is the swvController's back button on navbar is not responding – sandy 3 hours ago
3rd approach:
SWVController *swvController = [[SWVController alloc] init];
UINavigationController *viewNavController = [[UINavigationController alloc] initWithRootViewController:swvController];
SampleAppAppDelegate *appdel = [[UIApplication sharedApplication] delegate]; [appdel.viewController presentModalViewController:viewNavController animated:YES];
>> result is working fine, but the problem is i dont want to use SampleAppAppDelegate,i want to give my small Uiview (100x80) as a ctrl to other person , where my ctrl will not able to get the AppDelegate of thet app at run time. – sandy 3 hours ago
Call this method when you want to present the modal view controller:
- (IBAction)showInfo {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
Add this method to your self:
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
Use a toolbar or other button and connect it to this method in your modal view controller:
- (IBAction)done {
[self.delegate flipsideViewControllerDidFinish:self];
}
All code comes from Apple.
How did you handled click/touch on UIImageView? TouchesBegan/Ended?
Try putting some logs (NSLog) and run your app in debug mode (put some breakpoints) to see if control reaches your action method...
Also, when you do presentModalViewController, you do not need to POP out with back button on navigation bar... you only need to dismissModelViewController to hide it.