Question

I have an exception happening that I just can't figure out. I have this bit of code here:

newControllers = [[NSMutableArray alloc] initWithCapacity:9];  // Only allocate what we need


    // Ok, add the new thumb UIs
    for (int i = 0; i < 3; ++i) {

        for (int j = 0; j < 3; ++j) {

            // Create the view controller
            ThumbViewController *newThumbVC = [[ThumbViewController alloc]
                                                   initWithNibName:@"NewThumbDisplayView" bundle:nil];
            // Set the info
            newThumbVC.localInfo = [newInfo objectAtIndex:(i * 3) + j];

            // Place it properly
            [self.scrollViewContent addSubview:newThumbVC.view];
            CGRect rect = CGRectMake(8 + (j * 99), 363 + (i * 134), 106, 142);
            newThumbVC.view.frame = rect;
            [self.scrollViewContent bringSubviewToFront:newThumbVC.view];

            [newControllers addObject:newThumbVC];
        }
    }

When running on the simulator, this works just perfectly. This morning I tried to run it on my phone, and I get an exception when calling CGRectMake with the following stack (Note that nothing is printed out in the output window at all making this more of a pain to figure out).

Thread 1, Queue : com.apple.main-thread

    #0  0x35220238 in objc_exception_throw ()
    #1  0x3751b788 in +[NSException raise:format:arguments:] ()

If anybody can point out to me what exactly is not right here, I would be very grateful.

Was it helpful?

Solution 2

This turned out to be a problem with a version mismatch between my iOS version on my device and the version of XCode I was running. Updating XCode took care of everything.

OTHER TIPS

CGRectMake is just a macro so it's not the problem. You really only need one view controller and have it manage a set of views rather than have a set of controllers. Having multiple controllers is highly discouraged.

I think you're seeing a race condition on building the ThumbViewController's views which are built lazily after the nib is loaded. I think the crash is happening when you add the new vc's view as a subview, which on the simulator might get built quickly enough to be non-nil.

The SDK does not encourage multiple VCs in charge at once (with only a few exceptions like MPMoviePlayerController). Do you really need VCs for the thumbs? Just by the name, they sound more like views.

If you must use VCs, then you'll need to pass them their row/col and have them frame themselves in viewDidLoad (or later).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top