为什么我在设备上使用Array但在模拟器中没有异常?

时间:2013-07-13 15:46:09

标签: ios runtime-error nsset

'NSInvalidArgumentException',原因:' - [__ NSCFSet addObject:]:尝试插入nil'

为什么我在运行下面的代码时在iPhone 5.1中而不是在6.0模拟器中出现此异常?此代码适用于幻灯片视图控制器,这是否支持5.1?

- (NSArray*)controllers {
    NSMutableArray *result = [NSMutableArray array];
    if (self.centerController) [result addObject:self.centerController];
    if (self.leftController) [result addObject:self.leftController];
    if (self.rightController) [result addObject:self.rightController];
    if (self.topController) [result addObject:self.topController];
    if (self.bottomController) [result addObject:self.bottomController];
    return [NSArray arrayWithArray:result];
}

我认为这正是凯文所寻找的。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

IIViewDeckController* deckController = [self generateControllerStack];
self.leftController = deckController.leftController;
self.centerController = deckController.centerController;

/* To adjust speed of open/close animations, set either of these two properties. */
// deckController.openSlideAnimationDuration = 0.15f;
// deckController.closeSlideAnimationDuration = 0.5f;

self.window.rootViewController = deckController;
[self.window makeKeyAndVisible];
return YES;
}

- (IIViewDeckController*)generateControllerStack {
LeftViewController* leftController = [[LeftViewController alloc] initWithNibName:@"LeftViewController" bundle:nil];
RightViewController* rightController = [[RightViewController alloc] initWithNibName:@"RightViewController" bundle:nil];

UIViewController *centerController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
centerController = [[UINavigationController alloc] initWithRootViewController:centerController];
IIViewDeckController* deckController =  [[IIViewDeckController alloc] initWithCenterViewController:centerController
                                                                                leftViewController:leftController
                                                                               rightViewController:rightController];
deckController.rightSize = 100;

[deckController disablePanOverViewsOfClass:NSClassFromString(@"_UITableViewHeaderFooterContentView")];
return deckController;
}

0 个答案:

没有答案