Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem you're trying to solve is an <em>asynchronous</em> one. Your approach however is for solving a <em>synchronous</em> problem.</p> <p>For example, your class <code>CSAPromoModelController</code> is inherently asynchronous. This is because it's init method invokes an asynchronous method, and thus your class gets "infected" by asynchronism.</p> <p>You might consider a re-design, where class <code>CSAPromoModelController</code> becomes a subclass of <code>NSOperation</code> with a complete handler, e.g. <code>CSAPromoModelOperation</code>. It's <em>eventual</em> result is the array of images. The <em>imageArray</em> becomes an ivar of your <code>CSAPromoViewController</code>. The <code>CSAPromoViewController</code> will have a method for creating a <code>CSAPromoModelController</code> object which will be initialized with an image. The completion handler of the operation passes the array of images. Within the completion handler you basically execute the same statements as in your original <code>viewDidLoad</code> method in order to setup the controllers.</p> <p>You would use the operation as follows:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; self.pageViewController.delegate = self; NSURLRequest *request = ... CSAPromoModelOperation* op = [CSAPromoModelOperation alloc] initWithRequest:request completion:^(NSArray* result, NSError*error) { // assuming we are executing on the main thread! if (error == nil) { self.imageArray = result; CSAPageDataViewController* startingViewController = [self viewControllerWithImage:self.imageArray[0] storyboard:self.storyboard]; NSArray* viewControllers = @[startingViewController]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; ... } else { // handle error } }]; [op start]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload