Question

EDIT: The error is with the data structures that are being used during PDF generation. I'll be able to debug it once I can get a copy of OSX that supports iOS7. Thanks for all the help everyone!

At work I have Mac dedicated to working on iOS 6 apps. So far it hasn't been possible to update to a newer version of OSX so my version of XCode can't be upgraded to support iOS7 naturally. So long story short I can't debug iOS7 apps, so I am not sure why the app is crashing.

I have a UIActionSheet. I used to be using one with those completion blocks but was trying to debug so I have stripped everything away to just the basic barebones and it still crashes when I click on the button.

UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Send by Email", @"Send To...", @"Open In...", nil ];
[actionSheet showFromBarButtonItem:sender animated:YES];

That's just sitting on the end of a PDF generation method.

Any ideas? I've been researching this all afternoon and I haven't found any reason why it would stop working like this. I did try storing the action sheet as data in the view controller so the reference was being kept, but to no avail.

I am using ARC.

EDIT: I tried an UIAlertView with the same results. Maybe it's the PDF context ruining things somehow?

Thanks for all the help everyone.

EDIT: Big breakthrough in solving this one: When commenting out my PDF generation code that's before my action sheet/modal dialog/alert view, it opens without complaint. So it's some kind of hybrid issue, and I'll post the majority of my method here so everybody can see what's up:

-(void)shareTapped:(id)sender
{
    if (actionSheet.isVisible)
        return;

    if (![MFMailComposeViewController canSendMail])
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No mail setup" message:@"You must setup your email in the main settings app before you can share." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }

    for( NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows )       
    {
        // should only get run once due to UI
        Calculation* calc = [self.fetchedResultsController objectAtIndexPath:indexPath];
        NSString *filename = [calc.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSString *path = [[[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:filename] stringByAppendingPathExtension:@"ipc"];
        [[PPCalculation sharedInstance] openCalculation:path];
    }
    [[PPCalculation sharedInstance] calculate];

    // let's generate the PDF here!
    NSMutableData* pdfData = [[NSMutableData alloc] init];
    UIGraphicsBeginPDFContextToData( pdfData, CGRectZero, nil );
    UIGraphicsBeginPDFPage();

    // 200 lines of drawing commands here

    UIGraphicsEndPDFContext();

    // save to file
    NSString* path;
    for( NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows )
    {
        // should only get run once due to UI
        Calculation* calc = [self.fetchedResultsController objectAtIndexPath:indexPath];
        NSString* filename = [calc.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        path = [[[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:filename] stringByAppendingPathExtension:@"pdf"];
        [[NSFileManager defaultManager] createFileAtPath:path
                                                contents:pdfData
                                              attributes:nil];
    }

    // ActionSheet, modal dialog, composer dialog, alert view, all of them crash when I try to put them here
    UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:@"Share" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Send By Email", nil];
    [sheet showFromBarButtonItem:sender animated:YES];
}

Thanks again guys.

EDIT: It seems that, from my investigation and commenting things out line by line and sending them to the device over TestFlight that it's the internal data structures somehow not working properly, which is strange, as the rest of the app works fine. I probably will get a copy of Mountain Lion or something so I can debug this thing properly.

Was it helpful?

Solution 2

By sheer trial and error and commenting out code, I have narrowed it down to the PDF generation itself. Somewhere in the guts of the C++ data structures something is happening that is making iOS7 sad but the others fine. I've managed to convince the boss to order Mountain Lion so once that arrives I can build for iOS7 directly and debug it properly.

OTHER TIPS

Try below code... May be it will help you...

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Send by Email", @"Send To...", @"Open In...", nil];
//actionSheet.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.tag = ((UIButton*)sender).tag;
[actionSheet showFromRect:[(UIButton*)sender frame] inView:[(UIButton*)sender superview] animated:YES];

Try This it will help yo

your barbutton action method :

UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil: delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Send by Email", @"Send To...", @"Open In...", nil ];

[actionSheet showInView:self.view];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top