尝试使用iOS的可视化格式语言,但在尝试初始化约束时我得到了一个sigabrt。这段代码有什么明显的问题吗?
NSNumber *inset = [NSNumber numberWithFloat:TopBarInsetWidth];
NSNumber *width = [NSNumber numberWithFloat:TopBarButtonWidth];
NSNumber *height = [NSNumber numberWithFloat:TopBarButtonHeight];
NSDictionary *metrics = NSDictionaryOfVariableBindings(inset,width,height);
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(self.backButton);
NSArray *constraints =[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-inset-[self.backButton(=width)]|" options:0 metrics:metrics views:viewsDictionary];
答案 0 :(得分:1)
由于某种原因,Xcode没有给我任何类型的堆栈跟踪,而是默认为sigabrting。我通过将代码包装到try / catch块中并打破catch处理程序然后正确输出我的错误来解决这个问题。
答案 1 :(得分:0)
使用它:
NSArray * constraints = [NSLayoutConstraint constraintsWithVisualFormat:@“H:| -inset- [self.backButton(== width)] |” options:0 metrics:metrics views:viewsDictionary];