I have a modally presented view (call it 'current view'). It has an unwind segue to the modally presented view before it. Current view has a button hooked up to the following code:
- (IBAction)inviteUser:(id)sender
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController:picker animated:NO completion:nil];
}
Current view is set as the delegate to the picker and implements the following delegate methods:
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
// Do nothing
[self dismissViewControllerAnimated:NO completion:nil];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
[self dismissViewControllerAnimated:NO completion:nil];
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
return NO;
}
Nothing crazy so far. When I press the button, my contacts list comes up. I can select a contact and I'm sent back to current view with no crashes and no apparent changes.
Now, current view has another button (back button) hooked up to an unwind segue that I created in the storyboard. I did this by ctrl-dragging from the button to 'Exit' and picking the unwind function I had defined in previous view:
- (IBAction)unwindToThisList:(UIStoryboardSegue*)unwindSegue
{
}
Here's the clincher. If I press the back button while in current view, and I haven't gone into the address book while in this view, it unwinds correctly. No problems. I can go back and forth between those views all day. However, if I have gone into the address book and returned to current view, pressing the back button results in an EXEC_BAD_ACCESS. It makes no difference if I leave the address book by picking a contact or pressing cancel.
I'm completely lost. Pls halp.
I created a test xcode project, having two scenes in navigation,
Pushed the current view (second scene), from first View.
Then implemented the inviteUser method in current view, and I unwinded segue to the first view, after dismissing ABPeoplePickerNavigationController, without an error. Please check there migh be some other error, I guess.
Related
I am now using the tabbar controller and the uinavigation controller, when I call the MFMailComposeViewController by presentviewcontroller, and dismissed by dismissviewcontrolleranimated, I swipe back and click to push the viewcontroller again I found the back button is disappear and the title is wrong.
Tab-> ViewController [A] (Navigation Controller Embed) -(PUSH)-> ViewController[B] (with back button) -(Present)-> MFMailComposeViewController -(Dismiss)-> Show ViewController[B] -(Swipe Back)-> ViewController [A] -(Push) -> ViewController[B] (back button is disappear and the title is wrong)
Even I press back instead of swipe back, I found that there is still some problem not behave as usual navigation push controller
Many thanks if anyone could help!
After all these, ViewController[B] pop/swipe back to ViewController[A] viewdidappear and viewwillappear function in ViewController[A] are not triggered.
I have the exact same flow in my app, but I don't have any problem with the nav bar getting messed up.
Here's how the view controller is created:
MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
The delegate is set:
mailVC.mailComposeDelegate = self;
The view controller is presented:
[self presentViewController:mailVC animated:YES completion:nil];
The view controller is dismissed in the delegate method which is called when the user presses the Cancel button in the nav bar:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Hope this helps.
im have two view controller UserListView and UserProfileView!
in UserListView view controller i'm have a button for swtich to UserProfileView and here is code.
UserListView.m - Click Action
- (IBAction)SettingClick:(id)sender
{
UserList *UserProfile = [self.storyboard instantiateViewControllerWithIdentifier:#"UserProfileView"];
[self presentViewController:UserProfile animated:YES completion:nil];
}
And code working fine, when user switch to profile (UserProfileView) have a close button back to UserListView and here is code.
UserProfileView.m - Close click action
- (IBAction)CloseClick:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
UserProfile *UseList = [self.storyboard instantiateViewControllerWithIdentifier:#"UserListView"];
[self presentViewController:UseList animated:YES completion:nil];
}
in this code i will using [self dismissViewControllerAnimated:YES completion:nil]; to close UserProfileView view controller for low ram usage and it work.
But affter i close UserProfileView i want to open this view controller again and it do not work, UserProfileView not showing again??
i using xcode 5 and building an App for ios 7, please help.
Thanks for your time.
If I understand correctly, when you call SettingClick: your app is displaying a UserList. So, when you dismiss a view controller presented on top of it, you should go back to UserList without the need for presenting it again. So you can try with:
- (IBAction)CloseClick:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
This will work unless you had originally presented UserList as well. In this case, UserList will be dismissed with the top controller. In this case, you can delay presenting a second time UserList after dismissing UserProfile, and it should work.
In the latter case, I would suggest you to use a navigation controller instead of simply presenting your controllers like you are doing. As you see, it is not really straightforward and you will get into catches of any kind. Presenting a controller works ok when you present just one controller at a time. On the other hand, if you instantiate a UINavigationController, this will handle the controllers' hierarchy for you.
use this -
- (IBAction)CloseClick:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
This will return to your previous view when u click that button that has been linked with this action
My app basically has two view controllers, starting in a navigation controller:
1) MainViewController, which asks user to pick Camera or Album and then presents UIImagePicker
2) PhotoViewController, which receives photo.
However, in the second VC, when the user hits "Back", I would prefer to immediately return to either the Camera or Album they selected, rather than MainVC and then reloading the picker.
Should I separate an entirely new ViewController dedicated to the ImagePicker rather than presenting it within MainViewController? Using pushViewController: doesn't work as 'Pushing a navigation controller is not supported' perhaps meaning that imagePickers are nav controllers too.
MainViewController currently displays it like this:
[self.navigationController presentViewController:self.imagePicker animated:YES completion:nil];
Any suggestions appreciated, thanks.
A simple solution could be inside your MainVC have 2 bool values calledCamera, calledLibrary
when you create your new VC you set the one you choose your pic from to YES. So when you come back...
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (calledCamera){
//call cameraPicker to load before de MainVc shows
}
if (calledLibrary){
//call the LibraryPicker before...
}
}
I am working on a master-detail iPad application in xcode.
I have a button and textbox in my detail view. When the user clicks on the button, it calls a method from the MasterDetailViewController
- (IBAction)refreshButtonClicked:(id)sender {
[self.parent searchRSSWithURL:self.textBoxOutlet.text];
}
(self.parent is the MasterDetailViewController.) This method creates an array that is used to populate the table view in the MasterDetailViewController, and it is doing so successfully.
What I would like to do is also automatically open the Master View when the button is clicked so that the tableview can be seen, and I'm not sure how to approach that.
If you are using UINavigationController then
- (IBAction)refreshButtonClicked:(id)sender
{
[self.parent searchRSSWithURL:self.textBoxOutlet.text];
[self.navigationController popViewControllerAnimated:YES];
}
Other wise
- (IBAction)refreshButtonClicked:(id)sender
{
[self.parent searchRSSWithURL:self.textBoxOutlet.text];
[self dismissModalViewControllerAnimated:YES]; // OR [self dismissViewControllerAnimated:YES completion:nil];
}
I try 2 ways to dismissed 2 viewcontrollers consecutively but only one of them got dismissed not the second one
method1
-(void) LoginDone:(NSNotification *)notif
{
[self dismissViewControllerAnimated:YES completion:NULL]; //previous viewcontroller
[self dismissViewControllerAnimated:YES completion:NULL]; //current viewcontroller
}
method2
-(void) LoginDone:(NSNotification *)notif
{
[self dismissViewControllerAnimated:YES completion:NULL];
[[NSNotificationCenter defaultCenter] postNotificationName:#"LoginDone2" object:nil];
}
-(void) LoginDone2:(NSNotification *)notif
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
I need to find out a way to dismiss both the previous viewcontroller and current viewcontroller consecutively.
This is now an old question, but it seems to be exactly the problem I am having presently.
Here what I did:
[self.presentingViewController.presentingViewController
dismissViewControllerAnimated:YES completion:nil];
And it works for me. I hope it can be useful to someone.
By calling
[self dismissViewControllerAnimated:YES completion:NULL];
you are telling self to dismiss the view it presented. Telling twice the same self object to dismiss the view it presented, will not change the result. In other words self cannot represent the "current view" and the "previous view" at the same time as per your comment to the code. self is just a single controller representing a single view, either the current or the previous one.
To fix this, you should send the dismissViewControllerAnimated to self (that presented the top-most view, I assume) and to the other view controller object that presented the previous view.
In other words, I would expect something like this:
-(void) LoginDone:(NSNotification *)notif
{
[self dismissViewControllerAnimated:YES completion:NULL];
[self.previousController dismissViewControllerAnimated:YES completion:NULL];
}
Actually, you could send just one message to the second view controller and both views would be dismissed (source):
If you present several view controllers in succession, and thus build a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
I know this is an old question but maybe somebody will look for solution on this issue so here it is:
-(void) closeModalViews
{
[previousVC dismissViewControllerAnimated:YES completion:^(void) {
[self dismissViewControllerAnimated:YES];
}];
}
I like JPetric's idea, but first you must dismiss the current view controller's view and only then can you dismiss the presenting view controller's view.
[self dismissViewControllerAnimated:NO completion:^(void) {
[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
}];
As far as I could understand you are trying something like below:
There are 2 view controllers.
You want both of them to be vanished.
Another controller comes in.
But the fact is only one controller is displayed, why you would need to dismiss 2 then?
You can use self.view.hidden=true; on the jumped viewcontrollers while animating back to the first viewcontroller. Using [self.presentingViewController dismiss...] is not working for me without hiding.