I have a UIImagePickerController, and while it's loading, I want to display a disclaimer in a modalView.
- (void) viewDidLoad
{
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.delegate = self;
[self presentModalViewController:self.picker animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
DisclaimerController* disclaimer = [[DisclaimerController alloc] init]; // Loads the Xib inside the init method
UINavigationController* controller = [[UINavigationController alloc] initWithRootViewController:disclaimer];
[self.navigationController presentModalViewController:controller animated:YES];
}
But it doesn't shows up.
And I don't want to dismiss the picker while the disclaimer is showing or show it later, because there are some treatments that takes some time and the time the user reads the disclaimer would prevent him to wait too long after closing the disclaimer.
I would solve it using an AlertView.
But if you prefer using your method maybe this will do the trick
Try this:
- (void) showModalDisclaimer {
DisclaimerController* disclaimer = [[DisclaimerController alloc] init];
// Loads the Xib inside the init method
UINavigationController* controller = [[UINavigationController alloc]
initWithRootViewController:disclaimer];
[self.picker presentModalViewController:controller animated:YES];
// notice self.picker
}
- (void) viewDidLoad
{
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.delegate = self;
[self presentModalViewController:self.picker animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:NO
withAnimation:UIStatusBarAnimationNone];
[self performSelector:#selector(showModalDisclaimer) withObject:nil afterDelay:0.1];
}
Related
I have a simple 3 page app, I can go from page 1 to page 2 swiping left.
However, when I am on page 2, I need to add the ability to go to either page 1 swiping right, or page 3 swiping left, but it just keeps crashing.
I suspect it may be a memory release issue, but I wonder if you could be so kind as to check the code below for any glaring errors?
Many thanks,
- (void)viewDidLoad {
UISwipeGestureRecognizer *swipeLeftRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
[swipeLeftRight setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft )];
[self.view addGestureRecognizer:swipeLeftRight];
[UISwipeGestureRecognizer release];
}
- (IBAction)swipeLeftDetected:(UISwipeGestureRecognizer *)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
Page3ViewController *UIViewController =
[[Page3ViewController alloc] initWithNibName:#"Page3ViewController~ipad" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
[Page2ViewController release];
}else{
Page3ViewController *UIViewController =
[[Page3ViewController alloc] initWithNibName:#"Page3ViewController" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
[Page2ViewController release];
}
}
- (IBAction)swipeRightDetected:(UISwipeGestureRecognizer *)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
ViewController *UIViewController =
[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
[Page2ViewController release];
}else{
ViewController *UIViewController =
[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
ViewController *VC = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self presentModalViewController:VC animated:YES];
[Page2ViewController release];
}
}
EDIT:
You need to implement a method called handleGesture: since that's the action you're passing in to the gesture recognizer.
Fixed, I found an older post by a person called rptwsthi, I used some of that to fix it;
Changed the viewDidLoad {
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(rightSwipeHandle:)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:rightRecognizer];
[rightRecognizer release];
//........towards left Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:leftRecognizer];
[leftRecognizer release];
And using this to switch the pages;
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
//Do moving
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
ViewController *UIViewController =
[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
[Page2ViewController release];
}else{
ViewController *UIViewController =
[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
ViewController *VC = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self presentModalViewController:VC animated:YES];
[Page2ViewController release];
}
}
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
// do moving
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
Page3ViewController *UIViewController =
[[Page3ViewController alloc] initWithNibName:#"Page3ViewController~ipad" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
}else{
Page3ViewController *UIViewController =
[[Page3ViewController alloc] initWithNibName:#"Page3ViewController" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
}
}
Not sure how neat it is in a true coders view, but it works, sometimes you just gotta go with what works right! :)
I have a UIViewController with two UITableView's in it. When i select a row in the first UITableView it has to push the same UIViewController which doesnt happen.
In UIViewController.h i have,
FirstTableViewController *firstController;
SecondTableViewController *secondController;
In UIViewController.m i have,
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
if (firstController == nil) {
firstController = [[FirstTableViewController alloc] init];
}
if (secondController == nil) {
secondController = [[SecondTableViewController alloc] init];
}
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstController];
firstController.product = self.product;
[firstTable setDataSource:firstController];
[firstTable setDelegate:firstController];
firstNavigationController.view = firstController.tableView;
}
In FirstTableViewController.m, didSelectRowAtIndexPath i have,
[self.searchDisplayController setActive:YES animated:YES];
UIViewController *controller = [[UIViewController alloc]initWithNibName:#"UIViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
controller.product = prod;
NSLog(#"Navigation controller is %#",self.navigationController); //not null
[[self navigationController]pushViewController:controller animated:YES];
Please help.
EDIT #1: UIViewController is called from the FlipsideViewController of the UtilityApp.
Add a property to your AppDelegate UINavigationController *nav
add this line to AppDelegate.m in application didFinishLaunching method
navigationControl = [[UINavigationController alloc] initWithRootViewController:yourFirst ViewController];
Go to yourFirstViewController, add an UINavigationController *nav property and add these lines to viewDidLoad method
AppDelegate *app = [[UIApplication sharedApplication] delegate];
self.nav = app.nav;
Use this line to push any viewController
[self.nav pushViewController:controller animated:YES];
If you want to show a view controller modally, you should use presentViewController:animated:completion: and not pushViewController:animated:.
[self presentViewController:controller animated:YES completion:nil];
Use this Code in "didSelectRowAtIndexPath"
UIViewController *controller = [[UIViewController alloc]initWithNibName:#"UIViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[viewController release];
LoginViewSimpleController *loginViewSimple = [[LoginViewSimpleController alloc]init];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:loginViewSimple];
[self setNavigationController:navController];
Have you identify both tableviews ? Can you Post log status here ?
All
I have create UIImagePickerController with delegate and picking images from PhotoLibrary.
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
[self presentModalViewController:imagePicker animated:YES];
And when application reach to Editing view of UIImagePickerController i set one Overlay view and create two buttons for it.
Cancel and Choose
On Cancel Button click
[imagePicker popToViewController:[currentViewController.viewControllers objectAtIndex:1] animated:YES];
this cod work fine..
But choose Button does not working,
if i set code like here,
[self imagePickerController:imagePicker didFinishPickingMediaWithInfo:[imagePicker mediaTypes]];
than it returns NULL value of info dictionary.
Is that any other way to set overlay view on Editing ImagePicker ?
Regards,
try this code
CustomOverlayView *CustomOverlayView = [[CustomOverlayView alloc] initWithFrame:CGRectZero];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = YES;
[imagePickerController.view addSubview:CustomOverlayView];
[self presentModalViewController:imagePickerController animated:YES];
}
I've this method for opening the photoLibrary/camera in my view controller. But nothing happens when I call it (both simulator and device). I've implemented the delegate methods. No errors/warnings. I'm missing something?
- (IBAction) doButton {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = YES;
[self.navigationController presentModalViewController:picker animated:YES];
}
Should you not just call [self presentModalViewController:picker animated:YES];?
i create i navigationController project name:autoload,
then create two uiviewContorller named: second,three
i want the process is load rootView the load second in method:"viewDidLoad" then auto load three in method"viewdidload",
here is the code:
rootView:
- (void)viewDidLoad {
self.title = #"first";
Second *second = [[Second alloc] init];
AutoLoadAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:second animated:YES];
[super viewDidLoad];
}
second:
- (void)viewDidLoad {
self.title = #"second";
[super viewDidLoad];
}
now build an go the program, i can auto load to second very correct
includeing the title content and also the navgation button
then i want aotoload three in second,so add the code in second method:"viewdidload"
second:
- (void)viewDidLoad {
self.title = #"second";
**Three *three = [[Three alloc] init];
AutoLoadAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:three animated:YES];**
[super viewDidLoad];
}
finaly add the title to three:
three:
- (void)viewDidLoad {
self.title = #"three";
[super viewDidLoad];
}
then build and go, you will find that the content is right "three"
but the title is wrong "second", it should be "three"
and you will also find the navgation button is wrong
what's wrong with my that,what i should do to implement the program of autoload to three?
note:
i try that :
if i add a button in second and move the code
Three *three = [[Three alloc] init];
AutoLoadAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:three animated:YES];
to the ibaction ,it will be work correct, but i want it load automaticly
Instead of calling pushViewController in the viewDidLoad methods, try setting the viewControllers array in the applicationDidFinishLaunching method:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
RootViewController *root = [[RootViewController alloc] init];
root.title = #"root";
Second *second = [[Second alloc] init];
second.title = #"second";
Three *three = [[Three alloc] init];
three.title = #"three";
[navigationController setViewControllers:[NSArray arrayWithObjects:root,second,three,nil] animated:YES];
[root release];
[second release];
[three release];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}