At the beginning I had it like this but then I tried to change some things.
The point that makes me so angry is that I already had this error but I don't know how I solved it in the past
Post
Replies
Boosts
Views
Activity
VC1:
class NameVC: UIViewController, RegisterNameProtocol {
var name: String?
let vc3 = VerifyPhoneNumberVC()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
vc3.nameDelegate = self
}
@objc func goNext() {
The function which presents vc2
name = nametextField.text!
print("Name: \(vc3.Username)")
...
}
}
VC2:
class PhoneNumberVC: UIViewController, UITextFieldDelegate, RegisterNumberProtocol {
var phoneNumber: String?
let vc3 = VerifyPhoneNumberVC()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
vc3.phoneDelegate = self
...
}
func push() {
phoneNumber = phoneNumberTextField.text!
print("Number: \(phoneNumber)")
...
}
}
V3:
class VerifyPhoneNumberVC: UIViewController {
var nameDelegate: RegisterNameProtocol?
var phoneDelegate: RegisterNumberProtocol?
var UserphoneNumber = ""
var Username = ""
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
UserphoneNumber = (phoneDelegate?.phoneNumber) ?? ""
Username = (nameDelegate?.name) ?? ""
print("Number: \(UserphoneNumber), Name: \(Username)")
}
I think that's all:)
Of course, I thought it would be unnecessary, here I the code:
@objc func goNext() {
name = nametextField.text!
print("Name: \(name)")
if nametextField.text?.isEmpty == false {
let nextVC = PhoneNumberVC()
nextVC.modalPresentationStyle = .fullScreen
present(nextVC, animated: true, completion: nil)
} else {
print("No valid name")
}
}
Well that's all I have, what more do you need to see?
I already tried...
phoneNumber = (phoneDelegate?.phoneNumber) ?? ""
That doesn't work because it always takes the alternative data.
I also do not use segues because I don't use storyboards. The first view presents the second View and the second presents the third view.
Well @Claude31 and to all the others, thank you for your effort and help,
I'm going to delete the Code and try it new in a different way because there is definitely something really weird. I deactivated the whole CollectionView Code and it even showed me exactly the same error....
@Claude31
Exception NSException * "UICollectionView must be initialized with a non-nil layout parameter" 0x0000000282926a90
Is this what you need?
@OOPer
The collectionView is placed in a tableView Cell, that's the reason why the code will lack if you run it as normal CollectionView
@robnotyou I did that because the collectionView is in a tableView Cell, so I don't use the typical view.Anchor phrases...
@Claude31
Well, the error appears in the App Delegate
Yes I settled the frame but it also not worked :(
Okay, no it does not crash, the bottom view is visible when I tap on the bottom but you can't really see him because the cell Height doesn't fit.
This is the implementation in the tableView:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell {
if indexPath.row == 2 {
let priceSliderCell = tableView.dequeueReusableCell(withIdentifier: "PriceSlider", for: indexPath) as! PriceRangeCell
priceSliderCell.setUpTitleLabel(text: "Price")
priceSliderCell.setUpArrowButton()
priceSliderCell.setUpBottomView()
tableView.beginUpdates()
tableView.endUpdates()
tableView.deselectRow(at: indexPath, animated: true)
priceSliderCell.selectionStyle = .none
return priceSliderCell
}
This is the code for the cell Height:
//Cellheight IndexPath 2
let heightOfBottomView = CGFloat(95)
let basicHeight = CGFloat(50)
lazy var fullHeight = heightOfBottomView + basicHeight
var visibleBottomView = false
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) - CGFloat {
//...
if indexPath.row == 2 {
return visibleBottomView ? fullHeight : basicHeight
}
And this is the cell class:
class PriceRangeCell: UITableViewCell {
let Label = UILabel()
let bottomView = UIView()
var bottomViewIsVisible = false
var delegate: ExpandProtocol?
let arrowButton = UIButton()
let arrowConf = UIImage.SymbolConfiguration(pointSize: 20)
lazy var downImage = UIImage(systemName: "chevron.down", withConfiguration: arrowConf)
lazy var upImage = UIImage(systemName: "chevron.up", withConfiguration: arrowConf)
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(Label)
contentView.addSubview(arrowButton)
contentView.addSubview(bottomView)
bottomView.isHidden = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setUpTitleLabel(text: String) {
Label.text = text
Label.textAlignment = .left
Label.font = UIFont.systemFont(ofSize: 17, weight: .medium)
Label.tintColor = .black
Label.translatesAutoresizingMaskIntoConstraints = false
Label.topAnchor.constraint(equalTo: topAnchor, constant: 10).isActive = true
Label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 15).isActive = true
Label.heightAnchor.constraint(equalToConstant: 30).isActive = true
Label.widthAnchor.constraint(equalToConstant: 160).isActive = true
}
func setUpArrowButton() {
arrowButton.tintColor = .lightGray
arrowButton.setImage(downImage, for: .normal)
arrowButton.addTarget(self, action: #selector(expandView), for: .touchUpInside)
arrowButton.translatesAutoresizingMaskIntoConstraints = false
arrowButton.topAnchor.constraint(equalTo: topAnchor, constant: 10).isActive = true
arrowButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -15).isActive = true
arrowButton.widthAnchor.constraint(equalToConstant: 40).isActive = true
arrowButton.heightAnchor.constraint(equalToConstant: 40).isActive = true
}
@objc func expandView() {
if bottomViewIsVisible != false {
UIButton.animate(withDuration: 0.3) {
self.bottomView.isHidden = true
self.arrowButton.setImage(self.downImage, for: .normal)
}
bottomViewIsVisible = false
} else {
UIButton.animate(withDuration: 0.3) {
self.bottomView.isHidden = false
self.arrowButton.setImage(self.upImage, for: .normal)
}
bottomViewIsVisible = true
}
}
func setUpBottomView() {
bottomView.backgroundColor = .systemPink
bottomView.translatesAutoresizingMaskIntoConstraints = false
bottomView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
bottomView.topAnchor.constraint(equalTo: Label.bottomAnchor, constant: 5).isActive = true
bottomView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10).isActive = true
bottomView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10).isActive = true
bottomView.heightAnchor.constraint(equalToConstant: 60).isActive = true
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
I'm really thankful for your efforts!
Okay well, I did everything as you told me but it is still not working:(
Is it possibile that you used a function for the tableView or tableView Cell I maybe don't have defined?
Do you mean like this:
let heightOfBottomView = CGFloat(60)
let basicHeight = CGFloat(50)
lazy var fullHeight = heightOfBottomView + basicHeight
var visibleBottomViews : [Bool] = []
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) - CGFloat {
if indexPath.row == 0 {
//SegmentControl Rent of Buy
return 60
}
if indexPath.row == 1 {
//Segment Control Property Types
return 60
}
if indexPath.row == 2 {
//Price Slider
return visibleBottomViews[indexPath.row] ? fullHeight : basicHeight
}
if indexPath.row == 3 {
//Size Slider
return 118
}
}
This throws me the following error:
Thread 1: Fatal error: Index out of range
Ohh wow okay thank's. Maybe I was a bit too tired last evening for seeing this .... :D
Thanks man! That's great, I used the wrong function but the first two points you mentioned are correct, I just tried to delete the spaces between the lines of code to make it shorter