我在 FOR 循环中动态创建 UIButton 如下:
CGRect workingFrame = imgscrollView.frame;
workingFrame.origin.x = 0;
workingFrame.origin.y = 0;
for (int i=0 ; i < self.currentDetails.arrayOfImages.count ; i++)
{
UIButton *imageBtn = [[UIButton alloc] init];
[imageBtn setImage:image forState:UIControlStateNormal];
[imageBtn setUserInteractionEnabled:TRUE];
imageBtn.layer.cornerRadius = 8;
imageBtn.layer.borderWidth = 1;
imageBtn.layer.borderColor = [UIColor whiteColor].CGColor;
imageBtn.layer.masksToBounds = YES;
imageBtn.clipsToBounds = YES;
[imageBtn setContentMode:UIViewContentModeScaleAspectFill];
[imageBtn addTarget:self action:@selector(changeButtonImage:) forControlEvents:UIControlEventTouchUpInside];
[imageBtn setTag:i];
[imgscrollView addSubview:imageBtn];
imageBtn.frame = CGRectMake(workingFrame.origin.x+20, workingFrame.origin.y, 145, 140);
}
但是在设置它的frame的时候
imageBtn.frame = CGRectMake(workingFrame.origin.x+20, workingFrame.origin.y, 145, 140);
我收到以下错误,它崩溃了:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFString size]:无法识别的选择器发送到实例
我已经搜索过这个但找不到解决方案。
请帮帮我。
谢谢...
最佳答案
Size 方法适用于附加图像中的类
因为您在这里使用图像,请检查您是否有正确的图像实例。
关于ios - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : '-[__NSCFString size]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23026420/