我有一个自定义的类分段控件,每次选择分段控件中的不同项目时,都与视图控制器进行通信。我能够很好地将数据传递给视图控制器。但是,当我每次更新传递的变量时尝试使用某些基本逻辑时,“animateViews”函数内的所有项显然变为零。我收到臭名昭着的“意外发现无”错误。这只发生在我尝试使用我传递的变量时,一切按预期运行,否则在函数外部运行。调用函数时,函数中的项目变为零 - Swift 3
import UIKit
class MessagesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var messageTableView: UITableView!
@IBOutlet weak var boostCollectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
...all cells, delegates, and datasource are registered and setup in here.
}
func animateViews(selectedIndex: Int) {
if selectedIndex == 0 {
print("LEFT") // prints as expected
self.messagesTableView.isHidden = false // unexpected found nil error on each of these items.
self.boostCollectionView.isHidden = true
} else if selectedIndex == 1 {
print("RIGHT") // prints correctly when updated
self.messageTableView.isHidden = true
self.boostCollectionView.isHidden = false
}
}
}
我一直在玩这个左右的时间太长了,我怎么看法在animateViews功能隐藏和取消隐藏使用我从分段控制传递变量?
有可能是一个令人惊讶的简单的修复,我没有到这里,但我很感激你让你的眼球到目前为止。谢谢!
为什么有人会降低这个问题的投票率? –