处理iOS运行时错误

时间:2015-12-25 06:35:30

标签: ios objective-c

我已经被移交(投入到深层)的iOS应用程序的责任,该应用程序之前没有iOS编程经验。在我编写iOS编程书籍的同时,我试图在OS X El Captain(10.11.1)中使用Xcode 7,SourceTree运行在ObjectiveC中编写的应用程序。在Xcode中,target设置为iOS 8。

问题:我已将GiT的源代码从工作版本中提取到我的工作区,但不幸的是,即使在进行任何更改之前,我也遇到了运行时错误!尝试加载视图时代码中断:

- (void)loadView
{
    [super loadView];
    UIView* view = self.view;
    view.backgroundColor = [UIColor colorForBackgroundLight];

    SEFSDashboardHeaderView* headerView = [[SEFSDashboardHeaderView alloc] init];
    self.headerView = headerView;
    [view addSubview:headerView];

    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        UIView* topLayoutGuide = (UIView *)self.topLayoutGuide;
        make.left.equalTo(view);
        make.top.equalTo(topLayoutGuide.mas_bottom);
        make.right.equalTo(view);
        make.height.equalTo(@85);
    }];

    UITableView* tableView = self.tableView;
    tableView.rowHeight = 58;
    tableView.backgroundColor = view.backgroundColor;
    [view addSubview:tableView];
    self.tableView = tableView;

    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view);
        make.right.equalTo(view);
        make.bottom.equalTo(view);
        make.top.equalTo(headerView.mas_bottom);
    }];
}

违规行是:

make.top.equalTo(topLayoutGuide.mas_bottom);

在调试区域,当我在[topLayoutGuide.mas_bottom]上做一个po时,我得到:

(lldb)po [topLayoutGuide mas_bottom] 错误:警告:无法获取cmd指针(替换为NULL):没有名为' _cmd'的变量发现在这个框架中 执行被中断,原因:尝试取消引用无效的ObjC对象或向其发送无法识别的选择器。 该过程已返回到表达式评估之前的状态。 (lldb)

我的理解是topLayoutGuide对象中不存在属性 mas_bottom

但是,类massConstraintMaker.m中有 mas_bottom 的引用,其中包含以下代码:

- (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs {
    MASAttribute anyAttribute = MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX | MASAttributeCenterY | MASAttributeBaseline;

    NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)");

    NSMutableArray *attributes = [NSMutableArray array];

    if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left];
    if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right];
    if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top];
    if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom];
    if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading];
    if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing];
    if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width];
    if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height];
    if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX];
    if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY];
    if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline];

    NSMutableArray *children = [NSMutableArray arrayWithCapacity:attributes.count];

    for (MASViewAttribute *a in attributes) {
        [children addObject:[[MASViewConstraint alloc] initWithFirstViewAttribute:a]];
    }

MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
constraint.delegate = self;
[self.constraints addObject:constraint];
return constraint;

}

是否存在配置设置问题?我应该以不同的方式启动应用程序吗?我目前正在打开.xcworkspace文件而不是.xcodeproj。希望这是正确的方法。

如果我至少可以运行应用程序而没有任何运行时错误,那将是一个梦幻般的圣诞礼物!谢谢。

1 个答案:

答案 0 :(得分:-1)

通过删除XCODE 7.1并安装XCODE 6.4来解决问题。