作者:ERIK又 | 来源:互联网 | 2023-06-21 14:41
我的代码很快就开始在var myArray中声明一个空的imageviews数组。在didload视图中,我尝试在数组的开头插入第一个imageview。我的代码无法正常工作,myArray.insert(UIImageView,at: 0)
处出现编译错误。
然后在myArray[0].frame = CGRect(x: view.center.x-0,y: view.center.y+100,width: 50,height: 50)
出现运行时错误,表明它超出了索引范围。
import UIKit
class ViewController: UIViewController {
var myArray = [UIImageView]()
override func viewDidLoad() {
super.viewDidLoad()
myArray.insert(UIImageView,at: 0)
[myArray[0]].forEach({
$0.backgroundColor = UIColor.systemTeal
self.view.addSubview($0)
})
myArray[0].frame = CGRect(x: view.center.x-0,height: 50)
}
}
插入UIImageView()而不是UIImageView。
尝试以下代码:
public void insertAudit(Audit audit){
//Save Audit first to get auditId
Audit theAudit = auditRepository.save(audit);
//Loop audit.getAuditScopes() to manually set auditId
for(AuditScope scope : audit.getAuditScopes()){
scope.setAuditId(theAudit.getAuditId());
}
//Save all AuditScope with set auditId
auditScopeRepository.saveAll(audit.getAuditScopes());
/*
Expected result
auditRepository.save(audit);
auditScopeRepository.saveAll(audit.getAuditScopes());
*/
}