gpt4 book ai didi

ios - UIButton setFrame 无法识别的选择器 alignmentRectInsets

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:07:03 27 4
gpt4 key购买 nike

这是我第一次以编程方式添加 UI 元素。该应用因错误而崩溃:

2014-01-14 18:39:50.080 Convention[27580:70b] -[__NSCFConstantString alignmentRectInsets]: unrecognized selector sent to instance 0x10c028
2014-01-14 18:40:00.792 Convention[27580:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString alignmentRectInsets]: unrecognized selector sent to instance 0x10c028'
*** First throw call stack:
(
0 CoreFoundation 0x023f55e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01fe48b6 objc_exception_throw + 44
2 CoreFoundation 0x02492903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x023e590b ___forwarding___ + 1019
4 CoreFoundation 0x0242246e __forwarding_prep_1___ + 14
5 UIKit 0x00fe2305 -[UIButton alignmentRectInsets] + 217
6 UIKit 0x013b605b -[UIView(AdditionalLayoutSupport) alignmentRectForFrame:] + 52
7 UIKit 0x00fdf7f0 -[UIButton contentRectForBounds:] + 104
8 UIKit 0x00fe2448 -[UIButton layoutSubviews] + 100
9 UIKit 0x00dbd267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
10 libobjc.A.dylib 0x01ff681f -[NSObject performSelector:withObject:] + 70
11 QuartzCore 0x0029f2ea -[CALayer layoutSublayers] + 148
12 QuartzCore 0x002930d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x002a1715 -[CALayer(CALayerPrivate) layoutBelowIfNeeded] + 43
14 UIKit 0x00dafc76 -[UIView(Hierarchy) layoutBelowIfNeeded] + 595
15 UIKit 0x00fdb18c -[UIButton setFrame:] + 182
16 Convention 0x0006c020 -[CIFinalCustomerInfoViewController viewDidLoad] + 1760
17 UIKit 0x00e66318 -[UIViewController loadViewIfRequired] + 696

错误发生在执行 cancelButton.frame = CGRectMake(62.0, currentY+8.0, 162.0, 56.0); 期间。以下是代码:

- (void)viewDidLoad {
[super viewDidLoad];
BOOL contactb4ShippingConfig = ([ShowConfigurations instance].contactBeforeShipping);
originalBounds = self.view.bounds;
CGFloat currentY = 404.0;
if (contactb4ShippingConfig) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(62.0, currentY, 300.0, 35.0)];
label.font = [UIFont fontWithName:@"Futura Medium Italic" size:27.0f];
label.textColor = [UIColor whiteColor];
label.text = @"Contact Before Shipping";
[self.view addSubview:label];
[self.view addSubview:contactBeforeShippingCB];
currentY = currentY + 35.0;
}
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchDown];
[cancelButton setBackgroundImage:@"cart-cancelout.png" forState:UIControlStateNormal];
[cancelButton setBackgroundImage:@"cart-cancelin.png" forState:UIControlStateHighlighted];
cancelButton.frame = CGRectMake(62.0, currentY+8.0, 162.0, 56.0);
UIButton *submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
[submitButton addTarget:self action:@selector(submit:) forControlEvents:UIControlEventTouchDown];
[submitButton setBackgroundImage:@"submitorderout.png" forState:UIControlStateNormal];
[submitButton setBackgroundImage:@"submitorderin.png" forState:UIControlStateSelected];
submitButton.frame = CGRectMake(62.0, cancelButton.frame.origin.y, 260.0, 56.0);
currentY = cancelButton.frame.origin.y;
[self.view addSubview:cancelButton];
[self.view sizeToFit];
[self.view layoutIfNeeded];
}

最佳答案

问题是这些行:

[cancelButton setBackgroundImage:@"cart-cancelout.png" forState:UIControlStateNormal];
[cancelButton setBackgroundImage:@"cart-cancelin.png" forState:UIControlStateHighlighted];

将它们注释掉,一切都会好起来的。这表明我们未能找到有问题的图像。

稍后编辑好吧,我很粗心,恐怕;我完全通过反复试验找出了有问题的行,但我完全没有正确地注意到它们的问题什么!正如您所说的那样,这些是字符串,而不是图像。事实上,我们应该从原始错误消息中知道这一点:“-[__NSCFConstantString alignmentRectInsets]”的意思是在需要其他类的地方提供了一个字符串,所以我们所要做的就是查看对于代码中的一些流氓字符串。

(您的代码还有一些其他问题,但不是导致崩溃的那种问题。)

关于ios - UIButton setFrame 无法识别的选择器 alignmentRectInsets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21127070/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com