简体   繁体   English

在iOS设备(而非模拟器)上运行时,从CGRectMake获取异常

[英]Getting an exception from CGRectMake when running on iOS device (but not simulator)

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). 今天早上,我尝试在手机上运行它,并在使用以下堆栈调用CGRectMake时遇到异常(请注意,输出窗口中什么都没有打印出来,这让您很难理解)。

Thread 1, Queue : com.apple.main-thread 线程1,队列: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. 如果有人可以告诉我这里到底有什么不对劲,我将不胜感激。

CGRectMake is just a macro so it's not the problem. CGRectMake只是一个宏,所以这不是问题。 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. 我认为您在构建ThumbViewController的视图时遇到了竞争,这些视图是在装入笔尖后延迟构建的。 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. 我认为当您将新的vc的视图添加为子视图时,崩溃就发生了,在模拟器上它可能很快就被构建为非nil。

The SDK does not encourage multiple VCs in charge at once (with only a few exceptions like MPMoviePlayerController). 该SDK不鼓励同时负责多个VC(只有少数例外,例如MPMoviePlayerController)。 Do you really need VCs for the thumbs? 您真的需要VC吗? 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). 如果必须使用VC,则需要将它们的行/列传递给它们,并在viewDidLoad(或更高版本)中将它们自身构图。

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. 原来这是设备上的iOS版本与运行的XCode版本之间版本不匹配的问题。 Updating XCode took care of everything. 更新XCode可以处理所有事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在iOS设备上运行但不在模拟器中运行时,SIGABRT错误 - SIGABRT Error when running on an iOS device but not in simulator 数据不是从设备中的sqlite DB获取的,但可以在iOS Simulator中使用 - Data is not getting from sqlite DB in device but it is working in iOS Simulator 在模拟器3.2上运行时发生异常 - Exception when running on simulator 3.2 在模拟器中可以,但是在iOS设备中引发异常 - Ok in simulator but throwing exception in ios device iOS 应用程序在设备上自行运行时崩溃,在使用调试器或在模拟器中通过 Xcode 运行时不会崩溃 - iOS App Crashes when running by itself on device, does not crash when running through Xcode using debugger, or in simulator 在iOS设备而不是模拟器上运行代码 - Running code on iOS device instead of simulator iOS不同的输出,无论是在模拟器中运行还是在设备上运行 - iOS different output whether running in simulator or on device iOS5-应用在模拟器上运行但在设备上崩溃 - IOS5 - App running on Simulator but crashing on device 在iOS模拟器和设备上抛出异常时,Xcode调试器中缺少堆栈跟踪 - Missing stack trace in Xcode debugger when exception is thrown on both iOS simulator and device 为什么在设备上而不在模拟器上运行时会破坏数据? - Why a data will be destroyed when running on device but not on simulator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM