How to reload content of SlideNavigationController - ios

Actually i have created slide navigation by using this Slide Navigationcontroller
Now everything is working fine i have adjusted slide to left menu. but when i want to change it's content then at a time it does not work.
i have used this code in appdelegates for setting left menu and attached slidenavigation controller using storyboard as a root view controller of as a navigation controller
mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
employeeSlideNavigation *leftMenu = (employeeSlideNavigation*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"employeeSlideNavigation"];
[SlideNavigationController sharedInstance].leftMenu = leftMenu;
[SlideNavigationController sharedInstance].menuRevealAnimationDuration = .18;
Please suggest me how to reload left menu content. actually this code is in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
}

You can use this
Add observer with method inside the slideController class
#define NOTIFICATION_UPDATESLIDE #"UpdateSlideTable"
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(updateDetails:) name:NOTIFICATION_UPDATESLIDE object:nil];
-(void)updateDetails:(NSNotification*)notification
{
//content which you need to update
}
and post the notification from where you want to update the content of slide menu.
like this
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_UPDATESLIDE object:self];
Hope this helps you.

Related

able redirect to specify view controller after clicked remote notification but only VC but without navigation bar

i had setup an redirect after user click the push notification and it did worked. However the app is redirect to the View Controller without navigation bar and bottom toolbar.. Below are my redirect code : -
// Did receive notification method here...
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo NS_AVAILABLE_IOS(3_0)
{
NSLog(#"user info1 is %#",userInfo);
[[NSNotificationCenter defaultCenter] postNotificationName:#"NOTIFICATION_RECIEVED"
object:nil
userInfo:nil];
UIStoryboard *mainsboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [mainsboard instantiateViewControllerWithIdentifier:#"notice"];
[self.window.rootViewController presentViewController:vc animated:YES completion:nil];
This screenshot showing the notice storyboard properties
This screenshot showing the top navigation item properties
I think I understand the question to mean that you expect the view controller to appear in the context of a navigation controller that you have configured in storyboard. In that case, you'll need to do a little more to set things up:
find the navigation controller in your storyboard that contains the one with the "notice" ID, and give it a storyboard ID, too -- maybe something like "noticeNavigationController"
upon receiving the notification, build navigation controller from storyboard, too, and set it's root with the "notice" view controller that you know how to build...
// as you have it
UIStoryboard *mainsboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [mainsboard instantiateViewControllerWithIdentifier:#"notice"];
// but now build a navigation controller, too
UINavigationController *navVC = [mainsboard instantiateViewControllerWithIdentifier:#"noticeNavigationController"];
// make your vc the root
navVC.viewControllers = #[ vc ];
// and present** that navigation controller
[self.window.rootViewController presentViewController: navVC animated:YES completion:nil];
**Note, unless you're doing a presentation intentionally for some reason, it's more commonplace to just set the app's rootViewController to the navVC, rather than present it.

iOS: Reinitialize the the app from top view controller if it is coming from background

I want to reinitialize my app from top view controller problematically. I want my app reload the views from start.
I have tried this in applicationWillEnterForeground method:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
ActivityController *destViewController = (ActivityController *)[storyboard instantiateViewControllerWithIdentifier:#"ActivityView"];
[self.navigationController pushViewController:destViewController animated:YES];
But it doesn't work.
If you don't want your app to be running in the background, you can set UIApplicationExitsOnSuspend to true in your app's Info.plist
applicationDidEnterBackground and applicationWillEnterForeground,
[[NSNotificationCenter defaultCenter] postNotificationName:#"popToRoot" object:nil];
and in your rootViewController's viewDidLoad (that always appears on app launch) add this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(popToRootViewControllerAnimated) name:#"popToRoot" object:nil];
Then create a method in your rootViewController:
- (void)popToRootViewControllerAnimated
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
You should use [self.navigationController popToViewController:ActivityController animated:NO]; instead of popToRoot.
Refer this answer for more details.

NSNotification delay from class A to class B

My NSNotification is delayed.
In myVC, I have two buttons, buttonA and buttonB. Each one is linked to their respective pdfs, pdfA and pdfB. There is a button Push, which is pressed after A or B is pressed. Push brings the user to the RVC where there is a UIWebView.
I want it so that by pushing either A or B, the UIWebView will display the respective pdf file. To debug this, I set it so that instead of changing the pdf, it will display text using NSLog. However, it doesn't work until after go back to myVC from the RVC by pressing a different button.
in myVC.m file:
- (IBAction)open_pictures_A:(id)sender
{
//do some button alert popup action/whatever button does
RootViewController *dataObject = [RootViewController new];
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:dataObject
forKey:#"buttonA"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"MyNotification"
object:nil
userInfo:userInfo];
}
And there is one like that for buttonB, but forKey would be "buttonB"
in the viewDidLoad for myVC.m I have
[[NSNotificationCenter defaultCenter] postNotificationName:#"MyNotification"
object:nil];
in my RVC,
RVC.h I have
#property (nonatomic, strong) NSString *property1;
And in the RVC.m I have
- (void)viewDidLoad
{
// other stuff
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(eventListenerDidReceiveNotification:)
name:#"MyNotification"
object:nil];
}
- (void)eventListenerDidReceiveNotification:(NSNotification *)notif
{
if ([[notif name] isEqualToString:#"MyNotification"])
{
NSLog(#"Successfully received the notification from buttonB!");
NSDictionary *userInfo = notif.userInfo;
RootViewController *dataObject = [userInfo objectForKey:#"buttonB"];
// Your response to the notification should be placed here
NSLog(#"dataObject.property1 -> %#", dataObject.property1);
}
}
However, the log entry only shows up when I press a button to exit out of the RVC back to myVC
Here is the code I use to go from mVC to RVC
-(IBAction)goToRVC{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
RootViewController *RVC = [storyboard instantiateViewControllerWithIdentifier:#"Root"];
[UIApplication sharedApplication].delegate.window.RootViewController = RVC;
}
Then from RVC to myVC
-(IBAction)backtomyVC{
[[[UIApplication sharedApplication] delegate] performSelector:#selector(myVC)];
[self disconnect];
}
Why is my notification action being delayed?
It's not because of delay.
When you press your button A or B you create new RVC object and you post the notification however you don't present/push RVC view controller (you just initialise it) so the RVC hasn't fired viewDidLoad method and it hasn't register itself as an observer.
After that you call goToRVC method where you create RVC object and you add it to the view hierarchy so the viewDidLoad method is call and the object register itself as an observer.
When you go back to mVC the RVC is not deallocated yet so it receive the notification and you can see the log.
Hope it's clear.

Pushing iOS UIViewController from NSObject class

I have the following code within my AppDelegate. It is used during checks for In App Purchase expiry, and if a subscription is expiring, will present a popup for the user to choose to renew, and if they do, it will push the view controller for the In App Purchases onto the stack.
I would like to shift the code out of AppDelegate, and into its own NSObject class (just for tidiness). However, how do I call push the View Controller from another class?
self.window.rootViewController doesn't exist on the NSObject class, so of course won't function.
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UICollectionViewController *ivc = (UICollectionViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: #"IAPViewController"];
[navigationController pushViewController:ivc animated:YES];
In your NSObject class, when you want to push a vc, post a notification via NSNotificationCenter:
[[NSNotificationCenter defaultCenter] postNotificationWithName:#"PushMyViewControllerNote" object:nil];
And in AppDelegate.m register observer:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(handlePushVCNotification:)
name:#"PushMyViewControllerNote"
object:nil];
//...
return YES;
}
//...
- (void)handlePushVCNotification:(NSNotification *)note
{
// First you must find currently visible view controller
// for how to do it, find it yourself :)
// but you can check https://gist.github.com/snikch/3661188
UIViewController *visibleVC = [self findVisibleVC];
UINavigationController *nc = visibleVC.navigationController;
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UICollectionViewController *ivc = (UICollectionViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: #"IAPViewController"];
[nc pushViewController:ivc animated:YES];
}
What you should do is create a separate class that inherits from NSObject. Call it something like AppPurchase. Then, import your AppPurchase class into your app delegate. As for pushing the view controller, that code should be separate from your AppPurchase class.
The AppPurchase class is part of your Model, and should not be responsible for pushing view controllers around. If data changes in your AppPurchase instance, then the controller can take some action and alter your View.
You should look into learning more about MVC or Model-View-Controller.

open a viewcontroller from storyboard when receive apple pushnotification

i am developing a app that has a storyboard with 3 view controllers and app in push notification enabled. and when i receive a push notification and when i tap on notification alert it should open a second view controller from my storyboard let me show my code.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"pushNotification" object:nil userInfo:userInfo];
}
and then storyboard loads which is actually my first view controller which also have a button in it to second view controller and that is the controller i want to load. and here is the code in my first view controller.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(pushNotificationReceived) name:#"pushNotification" object:nil];
}
-(void)pushNotificationReceived{
NSString * storyboardName = #"DealerMainStoryboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"DealerBuyRequests"];
[self presentViewController:vc animated:YES completion:nil];
}
so when i receive notification with this code app crashes when i tap on notification.
You need to get some error log but check this.
UIViewController * vc =
[storyboard instantiateViewControllerWithIdentifier:#"DealerBuyRequests"];
I don't think you want to create a new UIViewController , unless you really named your controller "UIViewController".
So check again the class name of the View you want to present modally
DealerBuyRequestsViewController * vc =
[storyboard instantiateViewControllerWithIdentifier:#"DealerBuyRequests"];
Make sure the StoryBoard Id of this View controller matches DealerBuyRequests or you will get errors.

Resources