jampez77
jampez77

Reputation: 5231

App crashes on loading modal window

So I'm new to working with Xcode and trying to fix an existing app. The trouble I'm having is with loading in a HTML file into a modal window.

This is the code I think is relevant:

-(void) loadScreen
{
    [super loadScreen];


    formView = [[ontracHazardsFormSheetViewController alloc] init];
    [formView setModalPresentationStyle:UIModalPresentationFormSheet];
    formView.urlToLoad = [self.urlToLoadstringByAppendingString:@"/redzone"];
    formView.cookieValue = self.cookieValue;
    formView.dataObject = self.dataObject;
    formView.htmlString = self.redzoneHTMLString;
    [formView loadScreen];


}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.


    NSMutableArray *array = [self.navigationItem.rightBarButtonItems mutableCopy];

    UIBarButtonItem *redZoneButton = [[UIBarButtonItem alloc] initWithTitle:@"Red Zones" style:UIBarButtonItemStylePlain target:self action:@selector(displayRedZones:)];
    redZoneButton.tintColor = [UIColor redColor];
    [array addObject:redZoneButton];
    self.navigationItem.rightBarButtonItems = array;

}
-(IBAction)displayRedZones:(id)sender
{
    NSLog(@"red zones");


    [self presentViewController:formView animated:NO completion:nil];


    //ontracWebViewController

}

I have a button that launches displayRedZones and when I use it the following crash report is produced:

2016-03-30 14:05:55.539 eCoss[3680:1292033] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[_UIAlertControllerActionSheetRegularPresentationController _defaultAnimationController]: unrecognized selector sent to instance 0x15710d10'
*** First throw call stack:
(0x2265c10b 0x21e02e17 0x22661925 0x2265f559 0x2258fc08 0x26b05e03 0x267a7651 0x26b05d69 0x2689a979 0x268c631d 0x268c50b1 0x22e697bd 0x2261fe1f 0x2261fa51 0x2261d89d 0x22570bf9 0x225709e5 0x237bcac9 0x26800ba1 0xd1ac1 0x2221f873)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Xcode also show this when the app crashes:

enter image description here

Like I said I'm completely new to using Xcode and IOS development full stop so if I've not included something crucial please forgive me and let me know.

thanks

Upvotes: 0

Views: 117

Answers (1)

Ronak Chaniyara
Ronak Chaniyara

Reputation: 5435

Use below code:

For iPhone:

[self presentViewController: formView animated:YES completion:nil];

For iPad:

UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:formView];

    [popup presentPopoverFromRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Like,

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    [self presentViewController:formView animated:YES completion:nil];
}
else {
    // Change Rect to position Popover
    UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:formView];
    [popup presentPopoverFromRect:CGRectMakeCGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

Note: Do modification as per reqiurement.

Upvotes: 1

Related Questions