IPhone App: Dismiss PopView On Button Click - iphone

In my iPhone App As shown below I have implemented PopViewController
Now on Button Click (Dismiss) I want to dismiss the pop view
How can I achieve that?

The simple answer to your question is
if ([PopViewController isPopoverVisible]) {
[PopViewController dismissPopoverAnimated:YES];
}
nevertheless, assuming you are using an external button there are many delegate issues that can play a part in this problem I suggest you refer to this post : Dismiss popover using UIbutton

try this:
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
add somting like #class ViewCntrollerClass2;

Try this
in .h
#protocol popOverDismissDelgate
-(void)dismissPopOverView;
#end
#interface ///
#property(nonatomic,assign) <popOverDismissDelgate> delegate;
#end
in .m
#synthesize delegate;
and write
-(void)dismissPopOverView{
[PopViewController dismissPopoverAnimated:YES];
}
when you creating second view controller to make popover view controller, set delegate to self like
SecondView *sv=[[SecondView alloc]initWithNibName:];
sv.delegate=self;
in second view controller implement this method
-(IBAction)buttonTapped{
[(id)delegate performSelector:#selector(dismissPopOverView)];
}
Tis will dismiss your popover view

Related

presentModalViewController not working in ios 5

Here I'd my code:
.h
IBOutlet SecController *SecContr;
.m
[self presentModalViewController:SecContr animated:YES completion:NULL];
The view controller is presented, but its view is not shown. How can I fix this? By the way I typed this on my phone. Also the iboutlet is definitely connected.
Why are you even creating an IBOutlet? You can use this code:
(IBAction)presentNextView:(id)sender
{
SecController *secCont = [[SecController alloc]init];
secCont.ModalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:secCont animated:YES];
[secCont release];
}
and then hook this up to a button, and you're good to go!
There is no presentmodalviewcontroller:animated:completion:.
You're thinking either of:
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;
or it's replacement:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
The view controller is presented, but its view is not shown
Then your whole question is irrelevantly titled and incorrectly explained. This has nothing whatever to do with how you present the view controller. It has to do with how the view controller obtains its view. You need to set up the relationship between the SecController class and its view. If a view controller can't find its view, it puts up an empty view; that sounds like what you're seeing.

Unloading a View in Objective-C (iPhone)

I have a View-based app. The first view that is loaded has a button which loads another view using this code:
AddPost *addView = [[AddPost alloc] initWithNibName:#"AddPost" bundle:nil];
addView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:addView animated:YES];
What I want to do is provide a button on the view (AddPost) that will let me close it and go back to the original view. How can I do this?
It seems a little strange, but you can actually have addView call:
[self dismissModalViewControllerAnimated:YES];
From the docs:
"The parent view controller is responsible for dismissing the modal view controller it presented using the presentModalViewController:animated: method. If you call this method on the modal view controller itself, however, the modal view controller automatically forwards the message to its parent view controller."
The answer Conrad gave will work perfectly well. In the name of slightly better encapsulation you could put a delegate protocol on addView and have your first view implement this.
So in the header file for your addView controller:
#protocol addViewDelegate <NSObject>
- (void)addViewRequestDismissal;
#end
You will also need an external properly on the addView controller:
#property (assign) id<addViewDelegate> delegate;
Then make your first view controller implement this, so in it's .h file you should have
#interface firstView : NSObject <addViewDelegate> {
}
When you instantiate your addView remember to set the delegate:
addView.delegate = self;
In the addView controller when your button is pressed call back:
- (void)buttonPressed {
[self.delegate addViewRequestDismissal];
}
Finally in your first view remember to implement this method
- (void)addViewRequestDismissal {
[self dismissModalViewControllerAnimated:YES];
}
Hope all goes well with this. Post back if you have any further problems :)

Parent View Controller and Model View Controller dismissal detection not working

I have a UIViewController called ShowListViewController that uses a Modal View Controller to push another view onto the stack:
AddShowViewController *addShowViewController = [[AddShowViewController alloc] init];
[addShowViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:addShowViewController animated:YES];
I would then like to call my method populateTableData of the ShowListViewController class when the addShowViewController disappears.
I would think that the answer found here would work, but it doesn't. My method populateTableData is not detected as an optional method to use.
Essentially my questions is: How do I detect when a Modal View Controller disappears so as to call a method within the class that pushed it on the stack?
This may not be a best solution, but can do what you want at this time.
In your showlistcontroller add an instance variable like
BOOL pushedView;
#implementation ShowListViewController
and before you do the modal presentation set its values as YES like
pushedView = YES;
[self.navigationController presentModalViewController:popView animated:YES];
in the viewWillAppear of ShowListViewController you can detect whether it is appearing because pop getting dismissed or not like
if (pushedView) {
NSLog(#"Do things you would like to on pop dismissal");
pushedView = NO;
}
I think you would like something like this.
You make a delegate inside ur modalVC like this:
#protocol ModalViewDelegate <NSObject>
- (void)didDismissModalView;
#end
and implement it in your MainVC like this:
#interface MainViewController : UIViewController <ModalViewDelegate>
{
Then u will make a delegate property in your modalVC like this:
#interface ModalShizzle : UIViewController
{
id<ModalViewDelegate> dismissDelegate;
}
You set the dismissDelegate of your ModalVC to your MainVC and then you make the delegate method. Before you dismiss it however you will call the ModalVC to do one last thing. (which is populate your table). You will call for the data inside your MainVC and then do whatever you feel like it, just before you dismissed your modalVC.
-(void)didDismissModalView
{
//call ModalVC data here...
//then do something with that data. set it to a property inside this MainVC or call a method with it.
//method/data from modalVC is called here and now u can safely dismiss modalVC
[self dismissModalViewControllerAnimated:YES];
}
Hope it helps ;)
OK so it appears that in Apple's template for Utility App's they ignore what the docs for [UIViewController][1] say and actually go out of their way to call dismissModalViewControllerAnimated: from the UIViewController that pushed the modal view onto screen.
The basic idea in your case will be
Define a protocol for AddShowViewControllerDelegate
Make ShowListViewController implement this protocol
Call a method on the delegate to ask it to dimiss the modal view controller
For a full example just create a new project with Utility template and look at the source for FlipsideViewController and MainViewController
Here is an example adapted for your needs:
AddShowViewController.h
#class AddShowViewController;
#protocol AddShowViewControllerDelegate
- (void)addShowViewControllerDidFinish:(AddShowViewController *)controller;
#end
#interface AddShowViewController : UIViewController
#property (nonatomic, assign) id <AddShowViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
#end
AddShowViewController.m
- (IBAction)done:(id)sender
{
[self.delegate addShowViewControllerDidFinish:self];
}
ShowListViewController.h
#interface ShowListViewController : UIViewController <AddShowViewControllerDelegate>
{
...
}
ShowListViewController.m
- (void)addShowViewControllerDidFinish:(AddShowViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
[self populateTableData];
}

UIView notification when modal UIImagePickerController is dismissed?

Is there a way to call code when a modal view is finished dismissing?
EDIT:
I'm sorry, I didn't clarify earlier. I'm trying to dismiss a UIImagePickerController and then show a MFMailComposeViewController and attach the image data to the email. When I try to call
[self presentModalViewController: mailController]
right after
[self dismissModalViewController];
I get errors and such.
You use a delegate pattern for the modal view to inform whoever presented it when it's finished.
MyModalViewController.h:
#protocol MyModalViewControllerDelegate;
#interface MyModalViewController : UIViewController
{
id<MyModalViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id<MyModalViewControllerDelegate> delegate;
#end
#protocol MyModalViewControllerDelegate
- (void)myModalViewControllerFinished:(MyModalViewController*)myModalViewController;
#end
MyModalViewController.m:
#synthesize delegate;
// Call this method when the modal view is finished
- (void)dismissSelf
{
[delegate myModalViewControllerFinished:self];
}
ParentViewController.h:
#import "MyModalViewController.h"
#interface ParentViewController : UIViewController <MyModalViewControllerDelegate>
{
}
ParentViewController.m:
- (void)presentMyModalViewController
{
MyModalViewController* myModalViewController = [[MyModalViewController alloc] initWithNibName:#"MyModalView" bundle:nil];
myModalViewController.delegate = self;
[self presentModalViewController:myModalViewController animated:YES];
[myModalViewController release];
}
- (void)myModalViewControllerFinished:(MyModalViewController*)myModalViewController
{
[self dismissModalViewControllerAnimated:YES];
}
EDIT:
I haven't used UIImagePickerController, but looking at the docs, it looks like you already have most of the code done for you, as there is an existing UIImagePickerControllerDelegate class that has three different "dismissal" delegate callbacks (although one is deprecated). So you should make your ParentViewController class (whatever that is) implement the UIImagePickerControllerDelegate pattern and then implement those methods. While each method will do something different (since you have to handle when the user actually selects an image, or if they cancel), they each will do the same thing at the end: call dismissModalViewControllerAnimated: to dismiss the picker.
You have to dismiss the modalViewController somehow right? Either a UIButton, or by code:
- (void)dismissModalViewControllerAnimated:(BOOL)animated
In the IBAction (e.g. delegate) for the UIButton or in the method above, call whatever code you want.
I don't think there is a specific notification yet can subscribe to, to know when dismiss animation is done,...BUT. You can implement viewDidAppear: in the view controller that presented the modal view. This is what I do, when I use the (to UIImagePickerController quite similar) ABPeoplePickerNavigationController.
In the callback from people picker, I remember the person tapped in the picker on an instance variable, like this:
- (void)callbackFromModalView:(id)dataFromModalView {
// remember dataFromModalView as I need it when dismissed
self.dataFromModalView = dataFromModalView;
// now initiate dismissal
[self dismissModalViewControllerAnimated:YES];
}
then, in your view controller, implement this:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (self.dataFromModalView) {
//...present now view here
// don't forget to reset this one
self.dataFromModalView = nil;
}
}
in effect, you are using the combination of viewWillAppear: and the dataFromModalView property as the "notification about modal view dismissed".

How to switch to next view when button is pressed iPhone?

here is a iPhone programming beginner's question:
How do I get to another view by pressing a button in my main view?
I have the following function which is executed when I press a button, and debugging it, he passes there, but my "Warning" view does not show up:
-(IBAction) showWarningView:(id)sender
{
if(self.showWarning == nil){
WarningViewController *nextView = [[WarningViewController alloc] initWithNibName:#"Warning" bundle:[NSBundle mainBundle]];
self.showWarning = nextView;
[nextView release];
}
[self.navigationController pushViewController:self.showWarning animated:YES];
}
My main RootViewController looks like this:
#import <UIKit/UIKit.h>
#import "WarningViewController.h"
#interface RootViewController : UIViewController {
IBOutlet UIButton *button1;
WarningViewController *showWarning;
}
#property(nonatomic,retain) WarningViewController *showWarning;
-(IBAction) showWarningView:(id)sender;
#end
I am using the navigation control of a UITableViewController but what do I have to use to just simply show my other view when I press a button in a view-based application?
Thanks a lot!
edited
if you're using the navigation control of a UITableViewController, you probably have to push the view in you tableviewcontrollers navigation controller
this means you have pass the navigation controller of your tableviewcontroller on to your viewcontroller, then you just push it
e.g.
[self.tableViewControllersNavigationController pushViewController:self.showWarning animated:YES];
(for passing the tableViewController's navigationController on, you might have to create a delegate pattern)
Does the title in your navigation bar change? Maybe you don't have a UIView associated with your UIViewController inside your Interface Builder file.