UIActivity Duplicate Calls to 'activityViewController' - iphone

I have a UIActivity that implements the activityViewController method. Everything works fine, except when a user quickly double taps on the icon for my activity. This causes duplicate calls to the method and crashes with:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller .'
I am using a custom UIActivityItemProvider as data that makes a server call (and can be slow) and this seems to be the cause of the issue.
How can I make sure two view controllers aren't being presented?
Note: This is being done through the UIActivityViewController so I don't think I have access to any buttons to disable them.

disable that button after first click, and enable after dismiss that activityViewController

Related

Unwind Segue nil argument error

I am new to ios development and I am trying to create a simple test app that allows users to record and edit their pills in their medicine cabinet.
I am using ios 6.1, arc and segues.
Background to the error:
So the user has a list of pills in their medicine cabinet, he picks one and a segue brings him to a view controller that gives him information about that pill. He then has the option to edit the info which segues him to another view controller that shows all the current info in textfields which he can edit and then click a save button which initiates an unwind segue to the original medicine cabinet.
The error I am getting is this. The user can edit the info and save it successfully and pop back to the cabinet. But then when he goes to edit the pill again, I get the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument'
I did some digging and I found out what is happening. In the unwind segue method,I am successfully setting the properties of the pill to match the text in the textfield of the editPillView controller. For example, I have a pill and it belongs to Jay. But then I edit it and say it belongs to Raf. Using breakpoints, I can see the string change from Jay to Raf in the unwind segue method of the MedicineCabinetViewController. But once the unwind segue is complete, I see that at some point, the string gets set to nil in apple's code (probably because arc is deallocing memory because the EditPillViewController is no longer needed and the pill's owner property then becomes a null pointer). Then when the user clicks the pill again, the pillInfoViewController is trying to use the null pointer and BOOM.
I've tried so many solutions to try to keep the string to stay raf such as using the NSString copy method. Any ideas?
When you do an unwind segue, any controllers from the one you're unwinding from, back to but not including the one you're unwinding to, will be deallocated unless you have a strong reference to them. So, the pill's owner property, if it's in MedicineCabinetViewController, will go away when the controller is deallocated.
There are several ways you can fix this problem. One way, would be to navigate in your app using code rather than using segues, so you can keep references to the controllers you create, and only allocate one if it doesn't exist yet.
Another way would be to have a model class that's a singleton, which would live for the life of the app. That way all the data concerning the medicines would be properties of some object (or objects) in this singleton class.

xib overlay in storyboard causing uncaught exception

My main app is using Storyboard's for laying all my views out. Next... I've also got a xib file that holds a few buttons that I'd like to apply in a fancy sort of overlay. This is also working great using a technique I found here: http://www.stackoverflow.com/a/12574190/949538
The Files Owner is hooked up to the main view controller. And from a button on my main view, I can pop open this xib nicely.
The problem comes from trying to attach an IBAction to anything I put on this xib. All of i have no warnings, no build errors, everything looks fine. Until I pop open the xib/view, and hit one of my buttons, then I get this:
2012-11-19 15:44:48.685 Frolfer[89367:c07] -[UIViewController closeStartPanel:]: unrecognized selector sent to instance 0x8352e90
2012-11-19 15:44:48.686 Frolfer[89367:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController closeStartPanel:]: unrecognized selector sent to instance 0x8352e90'
MainViewController.m
-(IBAction)closeStartPanel:(id)sender {
NSLog(#"close start panel");
}
It's got to be something just so basic that I'm forgetting / missing.
Any thoughts?
P.S.
There literally is not much code written yet, but if you'd like to see anything more just let me know. I'm not sure exactly what it is that you'd like to see...
Thanks in advance!!
- drew
Is there closeStartPanel: selector defined for that UIButton ? Can you post code for that? the exception clearly states that it is not able to find closeStartPanel selector for that UIButton in UIViewController...
I figured it out!
Not sure why I didn't try this before, but it works great now.
Usually when I'm in the Storyboard, I'd drag 'Touch Up Inside' handle over on top of my button to see the available IBActions's that I had created in my header. With the xib file, this wasn't happening at all. So as noted previously, I changed class of the Files Owner on my xib to my MainViewController.
After that, all my defined IBActions were appearing as I had expected them to when dragging 'Touch Up Inside' over to the button on screen in IB.
That's where the crashes started happening though.
This morning, I removed all associations to MainViewController on my xib file, and by accident, had drug the 'Touch Up Inside' handle over to First Responder. I guess I don't play with First Responder much... but to my surprise, all my IBActions were listed in there. For some reason, I thought I wouldn't see them.
After a clean and compile... boom, they worked! I guess the only downside (if you want to call it that), is that in the code view, it doesn't give an indication that your defined IBAction is hooked up to a button in the IB with the filled in gray dot like my other buttons that are directly on the storyboard do.
Oh well, seems to be working the way I had hoped (for now), so I'm going to just roll with it.
:-)
Have a great Thanksgiving weekend.
- Drew

how to create infinite looping in navigation controller like instagram application in iphone?

i am developing an application which would have many subviews like the flow of instagram and picyou kind of social networking apps the flow is image->detail image->any comment->username->following->username->image username->image->detail image->any comment->username->following->username->image username->damn this is infinite never stops.....
and never gets memory warning or crashed by memory issue...
i am using navigation controller but still after some time of navigation changing some viewcontrollers it gives me error like this *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported (<ViewController: 0x6d97110>)'
i want to do same like this on pressing back you will also get all datas back. do you have any idea how to do like this.?
UINavigationController automatically supports this behavior you are describing. Memory efficient and potentially infinite.
Every time you want to go from one piece of your app to the next you just use code similar to this.
ViewController *vc = [[ViewController alloc] init];
//customize ViewController
[self.navigationController pushViewController:vc animated:YES];
So if you want to go from a photo to a photo detail view, you just push the photo detail view controller when the button is pressed. Even if your in a photo detail view controller already you can push another one from that class. Just make sure you create a separate instance. Judging by your error, I think that is your problem now.
I have also found it best to create a custom initializer for these kinds of view controllers. For a photo detail view use something like.
-(id)initWithPhoto:(Photo*)photo;

crashing on ios device while navigation using UIModalTransitionStylePartialCurl in xcode 4

i am using UIModalTransitionStylePartialCurl on the ios 4 device,in my test app i have 2 classes where a single button in each class, in first page onclick of the button it ill navigate to 2nd page (by curling the page up) but in the 2nd page when i click backbutton its crashing but not navigating back to my first page
following is my code used for navigation
ViewController *MainWin = [[QIAViewController alloc] initWithNibName:NULL bundle:NULL];
MainWin.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:MainWin animated:YES];
[MainWin release];
this is the crash log:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nested modal view controller while curled <QIAAdminPassCnf: 0x583e040>.'
*** Call stack at first throw:
If you read the documentation for UIModalTransitionStylePartialCurl, you will see that once you've used it you can't present any more modal views.
If you want to navigate back, I think you should do,
[self dismissModalViewControllerAnimated:YES];
rather than creating a new view controller instance.
You may well have added the Action twice in Interface Builder. Go to the ViewController and to the Triggered Segues on the right and "x" do delete the extra one. LOL

UISplitViewController with NavigationControllers (including sample code)

The easiest way to see this problem will be to run the sample project here:
http://drop.io/stackproblem
Basically, It's a uisplitviewcontroller which can be switched between 2 detail views, both of which are navigation controllers.
The problem is that it crashes with the following error:
MultipleDetailViews[8531:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a view which does not have a window.'
It crashes with this error if you use the app in PORTRAIT and you navigate (still in portrait) from the first controller, to the second, to the first, to the second, and then boom CRASH using the popover controller.
One way to stop the crash is to stop lazy loading the navigation controllers and to load them fresh everytime but this isn't an option for the app I'm making.
Any ideas and I may fall in love.
Try using if (self.view.window != nil) just before the line that's causing the crash.