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.
Related
I am a master detail app which is embedded in tab bar controller. This loads from the beginning and works fine. Now, i want an initial page to load as soon as the app loads and then auto fade out to this screen without any event. How can i do the same? Please advice
You can add the initial viewController in the application:didFinishLaunchingWithOptions: method.
Present your initial controller ontop of the UINavigationController that holds the rootViewController (with no animation).
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourRootViewController];
self.window.rootViewController = navigationController;
UIInitialController *initialControlller = [[UIInitialController alloc] init];
initialControlller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
initialControlller.modalPresentationStyle = UIModalPresentationCurrentContext;
[navigationController presentViewController:initialControlller animated:NO completion:nil];
When you are ready to dismiss your initial you can do this (from the UIInitialController class) - with animation (you can set a NSTimer to call this method automatically):
[self dismissViewControllerAnimated:YES completion:nil];
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];
}
I am developing an e-com app for iPhone in which i need to open a view immediately when the user clicks on a button for the upcoming view, the data loads large images from server , to load images I am using a background thread .
Thank You
Simple, here's how to create a UIViewController and present it from within an IBAction.
- (IBAction)goToNextView:(id)sender
{
//if you are using xibs use this line
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"myXib" bundle:[NSBundle mainBundle]];
//if you are using storyboards use this line
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"myViewControllersID"];
//to present the controller modally use this
[self presentViewController:controller animated:NO completion:nil];
//or if you are pushing to this controller using a navigation controller use this
[self.navigationController pushViewController:controller animated:NO];
}
Be sure to pass animated NO so that the view is displayed immediately.
You need to make a button and then add its action like
-(IBAction)ButtonAction:(id)sender{
CalController *calculateView=[[CalController alloc] initWithNibName:#"CalController" bundle:nil];
[self.navigationController presentModalViewController:calculateView animated:NO];
}
You can use modal view controller for this
- (IBAction)showController:(id)sender {
SampleViewController *sampleView = [[SampleViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}
Here it is the tutorial http://timneill.net/2010/09/modal-view-controller-example-part-1/
I am using the RedLaser SDK. My app is a split view. I'm trying to launch a RedLaser overlay when a barbutton is pressed on the master view controller.
The method gets called when the button is pressed and that's where the problems start. I have 3 different versions of the code that launches the overlay. Each has it's own problem.
Option 1
This was my baseline and I knew it wouldn't work because I hadn't initialized the overlay. The following code launches the view controller correctly but (obviously) doesn't do what I want.
// Working Code that brings up dialog but doesn't start camera overlay
SRSScanVINViewController *scanVINViewController y= [[SRSScanVINViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:scanVINViewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:navController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Option 2
This code initiates the overlay controller and launches it without crashing. The overlay is working and the camera is active. The problem is that the viewcontroller/overlay is taking the whole screen. My controls (buttons, etc) are all layed out as if the view controller is taking a portion of the upper-left portion of the screen. This would work if I could get the overlay to be sized correctly.
// Working code that shows the overlay (camera on) but the overlay takes the whole screen
SRSScanVINViewController *scanVINViewController = [[SRSScanVINViewController alloc] init];
[pickerController setOverlay:scanVINViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:scanVINViewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:pickerController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Option 3
This attempt was to fix the problems in option 2 (above). Here is the code:
SRSScanVINViewController *scanVINViewController = [[SRSScanVINViewController alloc] init];
[pickerController setOverlay:scanVINViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pickerController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:pickerController animated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
It crashes with the following error (nslog):
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <SRSMasterViewController: 0x1f59f540>.'
*** First throw call stack:
(0x37ecb88f 0x331fc259 0x30d86441 0x7f6b5 0x7edf7 0x37e253fd 0x30cbfe07 0x30d855e7 0x37e253fd 0x30cbfe07 0x30cbfdc3 0x30cbfda1 0x30cbfb11 0x30cc0449 0x30cbe92b 0x30cbe319 0x30ca4695 0x30ca3f3b 0x3630522b 0x37e9f523 0x37e9f4c5 0x37e9e313 0x37e214a5 0x37e2136d 0x36304439 0x30cd2cd5 0x7deb5 0x7de50)
terminate called throwing an exception
Any help would be greatly appreciated. Thanks!
I got the code to work but still have a couple of issues. Here's the code:
SRSScanVINViewController *scanVINViewController = [[SRSScanVINViewController alloc] init];
[pickerController setOverlay:scanVINViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:scanVINViewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
pickerControllerPopover = [[UIPopoverController alloc] initWithContentViewController:pickerController];
[pickerControllerPopover setDelegate:self];
[pickerControllerPopover setPopoverContentSize:CGSizeMake(320.0f, 460.0f)];
[pickerControllerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}
else
{
[self presentViewController:pickerController animated:YES completion:nil];
}
This sets the size of the popover to the same size as my original controller (defined in the nib). I still have a couple of issues though.
The controller has 4 buttons in a button bar at the bottom. It also has a UIImage. The first time I load this controller, the buttons (and button bar and UIImage) are either missing are located in strange places. If I dismiss the popover controller by touching the screen somewhere outside of the controller and load the controller again, the controls are all in the right places. In fact, they are in the right places every time EXCEPT the first time.
Any ideas?
As shown in the screenshot below, i have a UITableView with some info and upon selecting a row an ABUnknownPersonViewController is invoked. In order to be able to able to dismiss that and go back to the UITableView I have this code:
ABUnknownPersonViewController *unknownPersonView = [[[ABUnknownPersonViewController alloc] init] autorelease];
[unknownPersonView setUnknownPersonViewDelegate:self];
[unknownPersonView setDisplayedPerson:personRecord];
[unknownPersonView setAllowsAddingToAddressBook:YES];
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Επιστροφή" style:UIBarButtonItemStylePlain
target:self action:#selector(goBackToView)];
unknownPersonView.navigationItem.title = #"Προσθήκη στις επαφές";
unknownPersonView.navigationItem.leftBarButtonItem = anotherButton;
navigationController = [[[UINavigationController alloc] initWithRootViewController:unknownPersonView] autorelease];
//navigationController = [[[UINavigationController alloc] initWithRootViewController:self] autorelease];
//self.navigationItem.rightBarButtonItem = anotherButton;
[self presentModalViewController:navigationController animated:YES];
} // didSelectRowAtIndexPath ends here
- (IBAction)goBackToView {
[self dismissModalViewControllerAnimated:YES];
}
- (void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonView didResolveToPerson:(ABRecordRef)person {
// CallerIDAppDelegate *delegate = (CallerIDAppDelegate *)[[UIApplication sharedApplication] delegate];
[navigationController dismissModalViewControllerAnimated:YES];
}
The problem (as you can see) is that when the ABUnknownPersonViewController is dismissed by the "Επιστροφή" button, which is "Back" actually, the view holding the tableView and the blue UIButton is moved a couple of pixels to the bottom!
Any help on what could be causing this?
Screenshot http://dl.getdropbox.com/u/1237004/problem.jpg
Debug this by checking your view's frame in -viewWillAppear, -viewDidAppear, -viewWillDisappear, and -viewDidDisappear.
Also check the view's autoresizingMask, and the parent view's autoresizesSubviews property.
I'm not sure I see the value of setting up a navigation controller here. You could just present the ABUnknownPersonViewController with [self presentModalViewController: unknownPersonView];. If you're doing it for the sake of picking up the visual navigation bar with the back button, then just add a nav bar and button to the unknown person view.
It seems like a mixed metaphor to be creating a UINavigationController but then not using its usual navigation methods (e.g., pushViewController:animated: and popViewControllerAnimated:) and instead using the modal methods inherited from UIViewController.
It seems that adding this line:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
in my viewWillAppear: made the view not to move when the modal view controller is dismissed. However now the initial position was already slightly dislocated to the bottom but fixed it by moving all the outles in IB to the top so it looks ok.