0

My application is a document based application I present the saved content using an UIViewController subclass EditViewsController with the help of my customized UIDocument object.

EditViewsController will look like below

enter image description here

Tapping the close Button on the left top corner will fire the below method

-(IBAction)closeForm:(id)sender
{
        // _formDocument is my UIdocument subclass Object
        [_formDocument closeWithCompletionHandler:^(BOOL completion){
                [self dismissViewControllerAnimated:YES completion:nil];
         }];
}

My problem is that while calling the method closeWithCompletionHandler my application freezes for a while before closing.

My question is that is it right to dismiss the viewcontroller without closing the document (simply call dismissViewControllerAnimated: inside the firing method) or I have to run that method in background thread to get rid of freezing?

vignesh kumar
  • 2,310
  • 2
  • 25
  • 39
  • 2
    completionHandler block appeared to be calling on background threads, you need to call dismissViewController on main thread as all UIKit events must happen on main threads. – ldindu Jan 07 '14 at 14:03

1 Answers1

0
-(IBAction)closeForm:(id)sender
{
    // _formDocument is my UIdocument subclass Object
    [_formDocument closeWithCompletionHandler:^(BOOL completion){
            [NSOperationQueue mainQueue] addOperationBlock:^{
                 // Dismissing it on main thread
                 [self dismissViewControllerAnimated:YES completion:nil];
            }];
     }];
}
ldindu
  • 4,270
  • 2
  • 20
  • 24
  • still no luck, But My app react quick after freezing for the first 3 or 4 time – vignesh kumar Jan 08 '14 at 05:39
  • Calling on above dismissViewCOntroller on main thread doesn't work for you, right? Are you having the same issue or has it been changed now? – ldindu Jan 08 '14 at 09:00
  • same issue before and after I updated the code you have posted – vignesh kumar Jan 09 '14 at 05:29
  • are you still encountering UI freezing problem, then there might be something wrong with other parts of your implementation? Calling "closeWithCompletionHandler:" on the document instance, UIDocument saves the document if there are any unsaved changes.However you also need to check block's completion argument, if it is true then your document is saved successfully else it is not saved due to some problem. – ldindu Jan 09 '14 at 09:18
  • How and where did you present it? – ldindu Jan 09 '14 at 09:33
  • [_formDocument closeWithCompletionHandler:^(BOOL sucess) the value of the varable 'sucess' is true – vignesh kumar Jan 09 '14 at 09:39
  • are you sure that dismissing view controller freezes your app? – ldindu Jan 09 '14 at 09:44
  • yes i'm sure about that but If I keep on opening and closing my document for many times the freezing stops at a point(may be after 3 or 4 times) – vignesh kumar Jan 09 '14 at 09:48
  • How did you create new or open existing document? – ldindu Jan 09 '14 at 09:49
  • My UIDocument object First load NSMUtableDictionary stored in local sandbox directory and then assign it to the property of UIDocument object. For creating I Assign a template NSMUtableDictionary object stored in bundle to the UIDocument property, If the user choose to save it before closing I send the save message to the UIDocument object and the NDMutableDictionary object in the property is written to disk – vignesh kumar Jan 09 '14 at 09:56
  • I haven't got any clue now. – ldindu Jan 09 '14 at 10:46
  • Me too can't understand this behaviour. that's why I planned to dismiss the view controller without closing the document. – vignesh kumar Jan 09 '14 at 10:48
  • what UIDocument's method call are you using to opening the document? – ldindu Jan 09 '14 at 10:49
  • I use the method [document openWithCompletionHandler:nil]; to open the document – vignesh kumar Jan 09 '14 at 10:51