Push next view Pagemenu ios xcode - ios

Hello I am using Page menu in application and i want to push from didSelectRowAtIndexPath in next view in one view which is involed in page menu
i know all way which we use for push and model.if i am using model with custom navigation bar then page menu hide on dismiss model.

Assumed hierarchy:
UINavigation Controller -- UIViewController -- UIPageController
UIPageController (with 2 UIViewController) -- UITableViewController-1 and UITableViewController-2
On didSelectRowAtIndexPath method
UIPageController -- UITableViewController-1 //Selected any one row
Then just push the next view controller onto the current UITableViewController.
Note - Both controller in UIPageController maintain separate life cycle that is independent from each other.

One can not push the viewcontroller in pageView , PageviewController don't have navigation controller .
Solution :
There are two ways to make this possible suggested by Nitin Gohel
set notification for event and Retrieve the notification on main Controller
You can send the information in Notification required in another viewController.
NSDictionary* userInfo = #{#"abc": #"aaa"};
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:#"One" object:self userInfo:userInfo];
In MainViewController just set the onserver for that notification in viewDidLoad method
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(OneNoti:) name:#"One" object:nil];
}
And perform push from MainViewController:
-(void) OneNoti:(NSNotification*)notification
{
NSDictionary* userInfo = notification.userInfo;
NSNumber* total = (NSNumber*)userInfo[#"total"];
NSLog (#"Successfully received test notification! %i", total.intValue);
NSLog(#"%#",notification.userInfo);
[self performSegueWithIdentifier:#"1_" sender:nil];
}
Set the delegate methods in MainView Controller and call the methods while performing action from page view and push from that Action .
Same like above way .

Related

How to dismiss multiple view controllers which have been presented not pushed?

Scenario:
I need to show 3 or more popups one after the other on button click in each popup. I have created a different viewcontroller and xib files for each popup. So for displaying each popup I have used presentViewController instead of pushViewController.
That is, I have used this:
[self presentPopupViewController:searchPopUpView animationType:0];
instead of
[self.navigationController pushViewController:searchPopUpView animated:YES];
For dismissing a popup, the following code has been written:
[self dismissPopupViewControllerWithanimationType:0];
Issue:
The popups are displaying perfectly, but the background gets darker and darker whenever a popup shows up. After all popups have been dismissed I have to finally click on the blank screen to remove those darker parts. How to overcome this issue?
I think you are using MJPopupViewController to show pop-up.
If it is so, Then try this.
Suppose there is a controllerA from which you want to show a pop-up controller popupControllerB.
Then in your controllerA add Notifications Observer
Code to write in controllerA :
// Add Notification Observer when your view initialise.
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(dismissPopup) name:#"DISMISS_POPUP" object:nil];
In viewWillDisappear remove the notifications observer
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
This method will be called when you Post-notification from your popupControllerB
-(void)dismissPopup {
[self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];
}
And In popupControllerB, Where you want to dismiss the Pop-up, write this code.
[[NSNotificationCenter defaultCenter] postNotificationName:#"DISMISS_POPUP" object:nil];
Above line of code will call a method written in your controllerA and dismiss the pop-up properly.
If you want to dismiss presented UIViewControllers you can use this code. I have used this approach to dismiss presentedViewControllers. It will dismiss all your presentedViewControllers on your rootViewController.
UIViewController* presVC = self.window.rootViewController;
while (presVC) {
UIViewController* temp = vc.presentingViewController;
if (!temp.presentedViewController) {
[vc dismissViewControllerAnimated:NO completion:^{}];
break;
}
vc = temp;
}

Pass data on dismiss to view controller outside of navigation controller?

As shown in the picture above, I have two view controllers, one of which is within a navigation controller. When a button is pressed in controller A, controller B is presented through the navigation controller and is displayed modally. Is it possible for me to pass data from controller B back to controller A when the dismiss function is called on B?
You can use delegation pattern or callbacks to do this
If you are using storyboards and navigating using segues, then an unwind segue will do this for you. Here is a simple tutorial that should help:
https://www.andrewcbancroft.com/2015/12/18/working-with-unwind-segues-programmatically-in-swift/
This stack overflow answer has much more detailed and valuable information on this topic
Passing Data between View Controllers
You can pass through NSNotificationCentre .
First you need to add Notification Observer and its selector in ViewControllerA as below :
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(receiveTestNotification:) name:#"notificationName"
object:nil];
-(void) receiveTestNotification:(NSNotification*)notification
{
NSDictionary* userInfo = notification.userInfo;
NSLog (#"%#",userInfo);
}
Now in ViewController B you need to post notification as below :
NSDictionary* userInfo = your data ;
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:#"notificationName" object:self userInfo:userInfo];

Is there a way to see if the current UIViewController appeared from the dismissal of another UIViewController

My question is that I have one main UIViewController that allows three other UIViewControllers to be presented through it, but I am wondering if there is a way that once I dismiss one of those other three controllers, can the main UIViewController be notified or tell that it is now appearing due to the dismissal of said controller?
Thank you in advanced!
If your main view controller implements:
(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
and the presented view controllers send it that message, you will know since at that time it can query to see what the "presentedViewController" was.
When you dismiss one of the three ViewControllers, you could signal to the main ViewController that they have been dismissed via a NSNotification:
NSDictionary *viewControllerInfo = #{#"ViewControllerClass" : NSStringFromClass([self class])}
[[NSNotificationCenter defaultCenter] postNotificationName:#"ViewControllerDismissed" object:nil userInfo:viewControllerInfo];
And in your main viewController:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(viewControllerDismissed:) name:#"ViewControllerDismissed" object:nil];
And respond with this method:
- (void)viewControllerDismissed:(NSNotification *)notification {
NSDictionary *viewControllerInfo = [notification userInfo];
// Dictionary should be same as the one passed through the noticiation.
}
Additional note: If you are using a UIStoryboard, then you can use an unwind segue.
EDIT: Updated Dictionary to use NSStringFromClass()

Can't access TabBarController from ImageView

I have an app that has a navigation controller in a tabbar controller. The root for the navigation controller is a table view controller. The table view has a segue to an image view. I want to update the badge value on a tab from the image view controller. From the tabbar controller, this works fine:
UIViewController *viewController = [self.tabBarController.viewControllers objectAtIndex:1];
viewController.tabBarItem.badgeValue = #"x";
But when I put the same code into the imageview controller, it doesn't work. When I check the value of 'viewController' after it executes, the value is nil. Same for self.tabBarController. For some reason the image view controller can't see its tabbarcontroller.
You should be able to access the tabBarController with self.navigationController.tabBarController. So your code needs to be:
UIViewController *viewController = [self.navigationController.tabBarController.viewControllers objectAtIndex:1];
viewController.tabBarItem.badgeValue = #"x";
so there are many ways to do this but the best way would be subcscribe to an NSNotification and then from your image view or wherever, make that notification so it would look something like.
[[NSNotificationCenter defaultCenter]
addObserver:objectToListen
selector:#selector(methodToRun:)
name:#"NotificationName"
object:nil];
And then in you deeper items such as the imageview or whatever you post it like this
[[NSNotificationCenter defaultCenter] postNotificationName:#"NotificationName" object:nil userInfo:dictionaryWithValuesForMethodToUse to use];
And then you get the information from the userInfo like so in you method that changes the badge value
- (void)methodToRun:(NSNotification *)notification
{
NSDictionary *dictionary = [notification userInfo];
}

MVC consistency, present a viewController from the model

I have a viewController I've built in storyboard. I also have a NSObject Subclass which acts as my model, which sends and listens for API requests and responses. When a method fires in my model, I want to present a modal View of my viewController from whatever view happens to be visible at the time.
An example would be if my API hears "show this view" I want to show viewController regardless of what view is being shown.
Conceptually, how does one do this?
EDIT: I don't know which view controller will be showing when I want to present my modal viewController. Also, I need to pass params from my model to the modalVC when it's presented.
I would send a notification from the model telling "someone" that some view needs be displayed.
NSDictionary *userInfo = #{ #"TheViewKey": viewToDisplay];
[[NSNoticationCenter defaultCenter] postNotificationName:#"NotificationThatThisViewNeedsToBeDisplayed" object:self userInfo:userInfo];
And then on the delegate (or the active view controller) would register to this notification and handle the display.
// self is the delegate and/or the view controller that will receive the notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleViewToDisplay:) name:#"NotificationThatThisViewNeedsToBeDisplayed" object:nil];
If you put in the view controller remember to remove self from the observers when the view is not visible:
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"NotificationThatThisViewNeedsToBeDisplayed"];
This way your model is decoupled from the presentation.
You have the current viewController (any viewController subclass) present the new view using:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
EDIT: To find the top view controller, you ask the UITabBarController for the selectedViewController (if you use a tabBarController) to get the 'seed', or start with the window.rootViewController.
Once you are past any tabBarControllers, then you should only have UIViewController subclasses and UINavigationControllers. You can use a loop like this:
- (UIViewController *)frontmostController:(UIViewController *)seed
{
UIViewController *ret;
if([seed isKindOfClass:[UINavigationController class]]) {
ret = [(UINavigationController *)seed topViewController];
} else
if([seed isKindOfClass:[UIViewController class]]) {
ret = seed.presentedViewController;
}
return ret ? [self frontmostController:ret] : seed;
}

Resources