AddThis API on an iOS Modal View - ios

I just started using the AddThis SDK for iOS in order to share URLs and images from my app.
I have a MainViewController, that calls a Modal View Controller named "SummaryViewController".
This segue is performed after a certain button is pressed on the Main View Controller.
There is a UIButton on "SummaryViewController" that is in charge of sharing on Facebook (or any other, for that matter), and performs:
-(IBAction)shareOnFacebook {
[AddThisSDK shareImage...];
}
The thing is that it works !
So where is the problem? When the user goes back to the Main View Controller, by pressing a "Back" button, opens the SummaryViewController for the second time and presses the "Share" button, the application crashes, with "unrecognized selector sent to instance", and sometime without any message, and the thread is stuck on [ATCoreController topViewController]
Any idea why this happens and how I can fix it? What is different between the first time the VC is shown and the second time?
Thanks a lot !!
in MainViewController.m:
- (IBAction)showSummary:(id)sender {
self.summaryViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"Summary ViewController"];
[self presentModalViewController:self.summaryViewController animated:YES];
}
in SummaryViewController.m:
- (IBAction)dismissModalViewController:(id)sender {
[super dismissModalViewControllerAnimated:YES];
}

There is a static method in addthis.h.
+ (void)setRootViewController:(UIViewController *)rootViewController;
You should set rootviewcontroller first time in default it sets your viewcontroller instance, but when you press back and again open summaryviewcontroller it searches for rootviewcontroller or top viewcontroller which was assigned previous one so if that's not available, your application crashes with bad excess.
So use this method to solve your problem before presenting pop-over.

Related

UIBarButtonItem causes app to crash

I'm learning to code in Objective-C by developing a simple app.
I'm using a UISplitViewController which has UIBarButtonItem.
When you tap an item on the left UINavigationController, shows up on the right one.
This right one has a button inside which takes you to a web site, controlled by a browser controller; when tapped, up left on the UIBar appears a button to go back/to the previous view.
The problem is that when I tap this button, the app crashes and Xcode tells me the problem is the method viewWillDisappear in the browser controller.
I've checked it up and down dozen times and can't find the error.
Change
[self viewWillDisappear : animated];
to
[super viewWillDisappear : animated];
Your way creates an infinite recursion - method calling itself - visible also in Thread 1 call stack.

How to pop viewcontroller in xcode6.1 story board?

Im using story board application. I want to add a button and when click on it I need to pop to the previous viewcontroller.
`
-(IBAction)done:(UIStoryboardSegue *)seque
{
[self.navigationController popViewControllerAnimated:YES];
}
`
But this is not working even though I set the action on exit on that button. But nothing happen. What should I do?
Please help me
thanks
It depends on whether your current ViewController was presented modally or via push. popViewControllerAnimated lets you pop the current ViewController which was added via push. As this takes no effect in your example, you most likely did present your ViewController modally requiring to call [self dismissViewControllerAnimated:YES completion:nil] to get rid of it.

remove all uiviewcontroller from hierarchy to display the first uiviewcontroller

When my App is starting I have a modal view controller to enter credentials (IP#, username, password...). When the user is logged he can open many UIViewControllers that can open others UIViewController and so on... These view controller can be navigation controller, tab bars, modals....
Next, the user can leave the application in background. Next, user can open the Mail App and open a mail that contains an attachment to navigate to my App. When the user select my App to open the attachment.
When the App moves in foreground I need to go to a specific viewController of the hierarchy (the first ViewController opened after the login screen).
To move the App to this first ViewController I have tried to use
– dismissViewControllerAnimated:completion:
but without success, there're still a view from the hierarchy that is still displayed.
Any idea how to do this?
Regards,
Sebastien.
If all the view controllers are in 1 Navigation controller and pushed onto the stack, you can simply use either popToRootViewControllerAnimated: or popToViewController:animated:
Otherwise, why not dismiss the first Modal view controller, then put it back with the view controller you want.
I found a solution with this small piece of code
UINavigationController* navc = (UINavigationController*)viewController.topViewController;
if (navc != Nil) {
if (navc.presentedViewController != Nil) {
[navc dismissViewControllerAnimated:FALSE completion:Nil];
}
[navc popToRootViewControllerAnimated:TRUE];
}
It was not complex at the end!
Sébastien.

Move to start of storyboard from button on last screen

I'm trying to get a storyboard to bring the user back to the first screen of a storyboard when a button is pressed.
I have the button click hooked up and the method is hit when it's tapped but it's either doing nothing or crashing the app depending on what I've got in that method (I've tried so many things at this stage that I can't remember the original setup)
The best I can achieve is that once tapped the user gets brought to the third screen in the storyboard, rather than the first.
Here's the storyboard, I want to get the user to move from the button circled in red back to the very first view controller (top left of screenshot).
Maybe the storyboard layout will help people, I'll post some of the various methods I've tried as well.
Here's the method
- (IBAction)done:(id)sender
{
//Multitude of attempts have been in here, either they don't do
//anything or they just send the user back to the NEW REPORT screen.
//Button does nothing in these following events
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
}
If you want to start fresh, have the button instantiate a new instance of the first controller, and set it as the window's root view controller:
FirstViewController *first = [self.storyboard instantiateViewControllerWithIdentifier:#"First"];
self.view.window.rootViewController = first;
It's not clear to me exactly how you're getting to that controller with the button in question, but you might want to put dealloc methods in all your controllers with a log to see if all are getting deallocated at some point in your navigation, and when you go back to the new first controller as I've outlined above.

ViewDidLoad Method is called again

I have two View Controller. In the first I do some stuff and then I can push the second View Controller by clicking a button (the button connected with the other ViewController in the storyboard). There I can do some settings and so on. I get back to the first View Controller with the button "Done". But then the ViewDidLoad method is called again and all the "stuff" (text in textfields, ...) is gone.
I hope you guys understand my problem.
Why? And how can I disable this?
How are you going back to the first view controller from the second one? I think your problem is you're re-instantiating the first view controller when the user hits "Done".
Instead, you should be using either "popViewControllerAnimated" or "dismissViewControllerAnimated" to go back to the first view controller.
e.g: (one of these 2 should work):
[self.navigationController popViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
Maybe the firstViewController is unLoaded because of receiving memory warning. So when it opened again, it calls ViewDidLoad

Resources